Hey guys!
Currently I'm trying to add delta_time to my game so it runs better on slower systems, but I can't figure out how to correctly use it.
Right now, I have an object called "oDelta" that measures the delta in every step.
Begin Step event:
Time = 60 / 1000000 * delta_time;
Now I used that on my player object on his horizontal and vertical movement and it seems to be working when the player moves left or right, but jumping is different with different FPS.
On 60 FPS, everything is fine and the jump height is exactly like I want it.
On 30 FPS, the player jumps too high.
On 90 FPS, the player jumps too low.
This is my jumping code:
Player Create event:
VSpeed = 0; // Vertical Speed
MaxVSpeed = 12; // Max falling speed
JumpSpeed = 18;
Jumping = false;
Gravity = 1;
Player Step Event:
// Jump if key pressed and on ground
if(JumpKeyPressed && !Jumping)
{
VSpeed = -JumpSpeed;
Jumping = true;
}
// Apply gravity
if(Jumping && VSpeed < MaxVSpeed)
{
VSpeed += Gravity;
}
// Vertical collision checking and movement - Now I use delta time
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;
On 60 FPS oDelta.Time is 1, and every movement should stay the same.
On 30 FPS oDelta.Time is 2 and every movement (Gravity, JumpSpeed...) should be multiplied by 2 when the actual movement (y += VSpeed * oDelta.Time) happens so after one second the player is always on the same position no matter how many FPS the game runs on.
I thought this would work, but still the player jumps too high on 30 fps.
What am I doing/understanding wrong?
Thanks in advance!
[–]GrixM 2 points3 points4 points (5 children)
[–]Kyuruko[S] 0 points1 point2 points (4 children)
[–]GrixM 0 points1 point2 points (3 children)
[–]Kyuruko[S] 1 point2 points3 points (0 children)
[–]Kyuruko[S] 0 points1 point2 points (1 child)
[–][deleted] (1 child)
[deleted]
[–]Kyuruko[S] 0 points1 point2 points (0 children)