Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's wrong with my code and how can I fix it? #16149

Open
Sonicfan0208 opened this issue Jan 12, 2025 · 1 comment
Open

What's wrong with my code and how can I fix it? #16149

Sonicfan0208 opened this issue Jan 12, 2025 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@Sonicfan0208
Copy link

Describe your problem here.

I'm trying to make a script that makes camera move upon hitting a note. up makes the camera go up, down makes the camera go down, left tilts the camera to the left, and right tilts the camera to the right. But everytime I try to use the script, the camera never moves when hitting the note.

btw, I'm using psych 1.0.

Here's my code:
var lerpVal:Float = FlxMath.bound(elapsed * 2.4 * cameraSpeed, 0, 1);
var offX:Float = 0;
var offY:Float = 0;
var offA:Float = 0;
var focus:Character = PlayState.boyfriend;
var curSection:Int = Math.floor(PlayState.curStep / 16);
var name = focus.animation.curAnim.name;

function onUpdate(elapsed)
{
if(!game.inCutscene && !game.paused && !game.freezeCamera)
{
if(PlayState.SONG.notes[curSection]!=null){
if (PlayState.gf != null && PlayState.SONG.notes[curSection].gfSection)
{
PlayState.focus = gf;
}else if (!PlayState.SONG.notes[curSection].mustHitSection)
{
focus = PlayState.dad;
}
}
if(focus.animation.curAnim!=null)
{
if(name.startsWith("singLEFT"))
{
offX = -20;
offA = 1.3;
}
else if(name.startsWith("singRIGHT"))
{
offA = -1.3;
offX = 20;
}
if(name.startsWith("singUP"))
offY = -20;
else if(name.startsWith("singDOWN"))
offY = 20;
}

    FlxG.camera.followLerp = 0.04 * game.cameraSpeed * game.playbackRate;
    FlxG.camera.angle = FlxMath.lerp(FlxG.camera.angle, 0 + offA, FlxMath.bound(FlxMath.bound(elapsed * 2.4 / 0.4, 0, 1) * game.cameraSpeed , 0, 1));
}
else 
{
    FlxG.camera.followLerp = 0;
}

}

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

@Sonicfan0208 Sonicfan0208 added the help wanted Extra attention is needed label Jan 12, 2025
@bpforest
Copy link

use game.curSection instead of var curSection.
change your all PlayState to game.
you must change gf to game.gf in the part where focus is designated as gf.
when checking character's animation, you don't updated the name after set focus to someone.
you didn't applied them after you defining offX, offY.
there's no code to check the section of the boyfriend.
remove lerpVal because it wasn't used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants