i have recently added delta into my game. it works fine for wasd movement but not the gravity. I have 2 variables for gravity. yMotion (the dynamic motion to change the y axis by every tick) and gravity (the multiplier of the falling). Each tick the yMotion goes down by gravity and then the y-axis is changed by yMotion. so if i set the yMotion to 2 for say, i will go up then it will fall.
my delta is the the ratio to to framerate. so if my rendering fps is a base of 60 and my actual fps is 30 my delta is 2. And if my rendering fps is 60 and my actual is 120 (somehow) then the delta is 0.5
well i need to add my delta framerate to my jumping and i cant get anything to work. heres my basic gravity/fall.
yMotion -= gravity; //gravity doesnt ever change.
if (!flying) { //if fly mode is on it skips this so the player doesnt go down
vector.y += yMotion;
}
heres where my jumping is at
if (jump && !inAir) { //in air is if the player isnt colliding with an object and jump is if the user if pressing space
yMotion = jumpingHeight*Game.delta; // Game.delta is the delta
}
to sum it up i need the delta to work. thanks!
Generally you have a velocity vector that you modify as you would in a constant-framerate game, and you multiply this velocity by delta to get the change in position.
Every frame, Velocity.X and Y = WASD_Input;
(Constant, no delta multiplication), and Velocity.Z += Gravity * Delta;
and finally Position += Velocity * Delta;
.
(Note: I use Z as the up/down axis, as that follows the mathematical standard for 3D models.)