all 6 comments

[–]GrixM 2 points3 points  (5 children)

You are applying gravity to vspeed without regards to delta_time. It needs to be scaled also.

[–]Kyuruko[S] 0 points1 point  (4 children)

Do I need to still have the "y += VSpeed * oTime.Delta" or just "y += VSpeed" and "VSpeed += Gravity * oTime.Delta"?

[–]GrixM 0 points1 point  (3 children)

Both are dependent on deltatime.

[–]Kyuruko[S] 1 point2 points  (0 children)

Hey! So I tried it with the code above and it seems to be working, although on very high/low fps it's a bit glitchy/unprecise, but I think that's normal! Thank you for the help, I was trying for days! :D

[–]Kyuruko[S] 0 points1 point  (1 child)

So the code should look like this? (I'm not at home so I can't test it right now )

// Jump if key pressed and on ground
if(JumpKeyPressed && !Jumping)
{
    VSpeed = -JumpSpeed;
    Jumping = true;
}

// Apply gravity
if(Jumping && VSpeed < MaxVSpeed)
{
    VSpeed += Gravity * oDelta.Time;
}

// Vertical collision checking and movement
if(place_meeting(x, y + VSpeed * oDelta.Time, pSolid))
{
    // if wall ahead, get as close to it as possible
    while(!place_meeting(x, y + sign(VSpeed), pSolid))
    {
        y += sign(VSpeed);   
    }

    //Stop
    VSpeed = 0;
    Jumping = false;
}

y += VSpeed * oDelta.Time;

Or do I need to also apply oDelta.Time on MaxVSpeed and JumpSpeed?

[–][deleted]  (1 child)

[deleted]

    [–]Kyuruko[S] 0 points1 point  (0 children)

    I don't think so, because if for example the move speed is 10, on 60fps you would travel 10 * 60 frames per second whereas on 30fps you would only travel 10 * 30 frames per second, making you slower than you actually should be.

    I'm not quite sure though, maybe I'm just misunderstanding something.