ShadowMario / FNF-PsychEngine

Engine originally used on Mind Games mod
Apache License 2.0
1.07k stars 2.12k forks source link

How to make arrows move back and forth. #15047

Open Average-FNF-Modder opened 1 week ago

Average-FNF-Modder commented 1 week ago

Describe your problem here.

I am a newbie at Lua coding, trying to make notes move back and forth to look all ghostly. Getting fucked.

local pencilsup = true
local pencilsmovement = true

function onCreate()
debugPrint(defaultOpponentStrumX0, 'defaultOpponentStrumX1', 'crochet')
end

function onSongStart(count)
        noteTweenAlpha('ghostlyNotes1', 0, 0.6, 0.1, 'linear')
        noteTweenAlpha('ghostlyNotes2', 1, 0.6, 0.1, 'linear')
        noteTweenAlpha('ghostlyNotes3', 2, 0.6, 0.1, 'linear')
        noteTweenAlpha('ghostlyNotes4', 3, 0.6, 0.1, 'linear')
        runTimer('startCycle2', 0.1, 1)
        runTimer('startCycle3', 0.2, 1)
        runTimer('startCycle4', 0.3, 1)
        noteTweenX('gNFloat1', 0, 150, 0.85 * 3, 'quadInOut')
        runTimer('back1', 0.85 * 3, 1)
end

function onTimerCompleted(tag, loops, loopsLeft)
    if tag == 'startCycle2' or 'forth2' then
        noteTweenX('gNFloat2', 1, 265, 0.85 * 3, 'quadInOut')
        runTimer('back2', 0.85 * 3, 1)
    elseif tag == 'startCycle3' or 'forth3' then
        noteTweenX('gNFloat3', 2, 380, 0.85 * 3, 'quadInOut')
        runTimer('back3', 0.85 * 3, 1)
    elseif tag == 'startCycle4' or 'forth4' then
        noteTweenX('gNFloat4', 3, 495, 0.85 * 3, 'quadInOut')
        runTimer('back4', 0.85 * 3, 1)
    elseif tag == 'forth1' then
        noteTweenX('gNFloat1', 3, 150, 0.85 * 3, 'quadInOut')
        runTimer('back1', 0.85 * 3, 1)
    elseif tag == 'back2' then
        noteTweenX('gNFloatBack2', 1, 200, 0.85 * 3, 'quadInOut')
        runTimer('forth2', 0.85 * 3, 1)
    elseif tag == 'back3' then
        noteTweenX('gNFloatBack3', 2, 300, 0.85 * 3, 'quadInOut')
        runTimer('forth3', 0.85 * 3, 1)
    elseif tag == 'back4' then
        noteTweenX('gNFloatBack4', 3, 400, 0.85 * 3, 'quadInOut')
        runTimer('forth4', 0.85 * 3, 1)
    elseif tag == 'back1' then
        noteTweenX('gNFloatBack1', 3, 100, 0.85 * 3, 'quadInOut')
        runTimer('forth1', 0.85 * 3, 1)

    end
end

function onTweenCompleted(tag)
    if tag == 'gNFloat1' then
        noteTweenX('gNFloatBack1', 0, 100, 1.25, 'quadOut')
    elseif tag == 'gNFloat2' then
        noteTweenX('gNFloatBack2', 1, 200, 1.25, 'quadOut')
    elseif tag == 'gNFloat3' then
        noteTweenX('gNFloatBack3', 2, 300, 1.25, 'quadOut')
    elseif tag == 'gNFloat4' then
        noteTweenX('gNFloatBack4', 3, 400, 1.25, 'quadOut')
    elseif tag == 'gNFloatBack1' then
        noteTweenX('gNFloat1', 0, 150, 1.25, 'quadOut')
    elseif tag == 'gNFloatBack2' then
        noteTweenX('gNFloat2', 1, 265, 1.25, 'quadOut')
    elseif tag == 'gNFloatBack3' then
        noteTweenX('gNFloat3', 2, 380, 1.25, 'quadOut')
    elseif tag == 'gNFloatBack4' then
        noteTweenX('gNFloat4', 3, 495, 1.25, 'quadOut')

    end
end

There is a bunch of code I (Badly) tried to do this with. It barely works. It moves the first 2 once and then stops. If anyone has a script that does this or just knows how to fix my broken code that would be cool.

Are you modding a build from source or with Lua?

Lua

What is your build target?

Windows x64

Did you edit anything in this build? If so, mention or summarize your changes.

No, I did not.

potatex2 commented 1 week ago

Reason why it only plays twice is because there isn't any other callback to the second set of tweens, but there are up to two ways to do this depending on what version of Psych you're playing on and if you want to incorporate some Haxe with Lua. First option you could do is a persistent tween for all the notes using math.sin() in the onUpdate() function (I will follow up on this tomorrow, it's 1 am ;-; )

potatex2 commented 1 week ago

Basically if you want to do this with both notes, you could use something like this (with the slight ghost effect on alpha of course):

function onUpdate(elapsed)
    noteTweenX(elapsed..'12',4,defaultPlayerStrumX0 + 1+(21*math.sin(getSongPosition()/400)),0.01)
    noteTweenX(elapsed..'22',5,defaultPlayerStrumX1 + 2+(21*math.sin(getSongPosition()/400)),0.01)
    noteTweenX(elapsed..'32',6,defaultPlayerStrumX2 + 3+(21*math.sin(getSongPosition()/400)),0.01)
    noteTweenX(elapsed..'42',7,defaultPlayerStrumX3 + 4+(21*math.sin(getSongPosition()/400)),0.01)
    noteTweenY(elapsed..'1',4,defaultPlayerStrumY0 + (11*math.sin(1+getSongPosition()/255)),0.01)
    noteTweenY(elapsed..'2',5,defaultPlayerStrumY1 + (11*math.sin(2+getSongPosition()/255)),0.01)
    noteTweenY(elapsed..'3',6,defaultPlayerStrumY2 + (11*math.sin(3+getSongPosition()/255)),0.01)
    noteTweenY(elapsed..'4',7,defaultPlayerStrumY3 + (11*math.sin(4+getSongPosition()/255)),0.01)
end

If you're using any version that supports runHaxeCode() though, something like

    runHaxeCode([[
        for (i in 0...playerStrums.members.length) {
            FlxTween.tween(playerStrums.members[i],{x: Math.sin(playerStrums.members[i].x) + playerStrums.members[i].x + 20},,{ease:FlxEase.sineInOut, type:FlxTween.PINGPONG});
        }
    ]])

would probably work too. (only thing is I haven't found out how to really delay each for a wavy effect like the one above)