- Home /
The faster it goes, the longer it jumps
Greetings;
I'm making a temple run type game. The players speed gradually increases. My problem is, I want the jump distance to be the same even if the forward speed is multiplied. For instance, if the player gets so fast, they could jump over 5 platforms, or 10 if I wasn't able to accomplish this.
Currently, for each time the forward speed is increased, I increase the gravity by a variable that I'm playing with, but I still havn't found the right amount. My tests are either too much gravity or too little gravity.
ForwardSpeed = 2 Gravity = 1.5
(increase speed here)
ForwardSpeed = 3 Gravity = 2
How do you think I can achieve the same jump distance? Is there some type of equation I could use to make this happen?
also, i'm very new to unity and 3D ga$$anonymous$$g creating, only been learning for last 30 days.
Answer by MarkFinn · Dec 02, 2012 at 02:16 PM
I've seen this one before. It's a bit trickier than it looks. Remember, if you increase gravity then the jump will have a lower trajectory, even if you get the distance right.
To have the same jump arc at higher horizontal speed you must modify both gravity and initial upward speed.
Been forever since I did this, so I've lost the base maths, but from my on code, looking back...
Take max height of the jump as a constant [H]. (In meters)
Take normal jump distance (on the flat) as another constant [D]. (In meters)
Time (In seconds) to spend in the air [T] = current horizontal speed (In meters per second) divided by [D].
Gravity (in meters per second per second) [G] = (2*H)/(([T]/2)^2)
Vertical jump speed (In meters per second) [V] = [G] * [T]/2.
Hope this helps. (Hope I've read my old math notes & code right (I was a lousy commenter back in the day).
thank you for this, I didn't think of modifying the jump speed at all. I'll try to get this working here shortly and post my success script.
Assu$$anonymous$$g this worked out ok, don't forget to set the question as answered/select the answer.
Thank you!! Finally, a jump that doesn't look like insane levitation skillz.