• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

My code is bugging out with frame perfect timing

T

The Green Dev

Guest
I was working on my main ground movement for my game when I found out that when you ran a certain direction then changed it to the opposite in a single frame, it would freeze the xsp.

Code:
dir = keyboard_check(ord("D"))-keyboard_check(ord("A"))

if dir != 0
{
    if abs(xsp) < wlk
    {
        xsp += acc*dir
        if sign(xsp) = dir
        {
            if abs(xsp) < msp
            {
                xsp = msp*sign(xsp)
            }
        }
        else
        {
            xsp += (skd-acc)*dir
        }
    }
}
else
{
    xsp -= min(abs(xsp), dec)*sign(xsp)
}

x += xsp
y += ysp

view_xview[view_current] = round(x)-view_wview[view_current]/2
view_yview[view_current] = round(y)-view_hview[view_current]/2
Any help please?
 

jo-thijs

Member
Then you're saying the issue is intentional.

Let me put it like this:
Does the freeze of xsp also happen if the player isn't at maximal horizontal speed yet?
You can easilly test this by setting the room speed to 1.
 
T

The Green Dev

Guest
Sorry, I fixed it, it turns out when you turn around within a frame, the game thinks you can't accelerate
 
Top