0

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!

gopro_2027
  • 103
  • 1
  • 9

1 Answers1

0

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.)

mcmonkey4eva
  • 1,359
  • 7
  • 19
  • thanks! this helped me find a solution. all i had to do was take away the delta multiplied on the jump and add in what you said – gopro_2027 Oct 30 '14 at 04:35
  • Don't forget to mark the answer as accepted (green check box) so other people don't think it still needs an answer. – mcmonkey4eva Oct 30 '14 at 04:40
  • btw i would like to add, how come almost all my game mechanics begin to break when i set the fps to 10? – gopro_2027 Oct 30 '14 at 04:40
  • Well... that could be a lot of things. That's a whole separate issue, would need more code to even begin to diagnose such a thing. – mcmonkey4eva Oct 30 '14 at 04:41
  • Generally you should aim for a minimum of 30 FPS though, to avoid... ugliness, visible lag, etc. – mcmonkey4eva Oct 30 '14 at 04:41
  • but if you are on a really slow pc like my old one, it might reach 10fps or lower. so im just testing it. im topping my game at 1024 fps although on ubuntu the max is capped at 60 for any program but not on windows. thats y i wanted to add delta today – gopro_2027 Oct 30 '14 at 04:42