# Speed needed to make a car jump from a ramp

(I've posted this question on GameDev and I've been told to ask here so I'm pasting the question)

I need to make a car jump from a ramp to another, and I need this to be done using AI so I thought it would be enough to set a fixed speed for my car when near the ramp, in order to let it jump correctly.

It works fine if I input the speed manually but I'd like my game to calculate it since the ramps will be generated by user's input.

Unfortunately my physics knowledge lacks, so I need your help.

The problem is summarized in the picture below.

Basically, what I need to compute is the speed (in m/s) that the car has to have on the highest point of the first ramp, given that all the data in red are user's input.

I had some rough ideas on using the projectile range with x=L, y=h-launchRampHeight but the results weren't as I expected them so I gave up.

Do you have any hints on this?

Please note that both ramps have the same length (50m) and that theta is expressed in degrees.

EDIT:

Based on the two replies I wrote some code and it seems to work fine but sometimes it returns a speed that's way higher than the correct one (which is not wrong but it's not the minimum one either).

For example, with theta = 8, L = 145, h = 12 it returns 100m/s (or maybe more, but the input's limited to 100m/s so it doesnt't show anything higher) while the jump works fine with 80m/s.

Well I tell you physically, you have to turn it to code yourself.

it's a simple projectile movement when we have:

$x =V_0tcos\theta$

$y=\frac{-1}{2} gt^2 + v_0tsin\theta$

where the $v_0$ is the initial velocity. and $\theta$ is the angle of thrown object.

if we want to get the equation without the time we will have:

$$y=\frac{-gx^2}{2V^2 \cos^2 (\theta)} + x\tan \theta$$

imagine that the place that the car is thrown (or jumped) the $(0,0)$ point. and $g$ is the acceleration that you defined in your engine (the gravity, I'm sure you know what the amount is in your engine). because you know the $\theta$ then all you need to do is to put the $(x,y)$ and calculate the velocity. before that I define a new variable $h'$ this way:

$h' =h-$**[height of my main ramp]**

and then put it in the main formula like this:

$$h'=\frac{-gL^2}{2V^2 \cos^2 (\theta)} + L\tan \theta$$

so the velocity will be equal to:

$$V=\sqrt{ \frac{-gL^2}{(h' - L\tan\theta) * 2 cos^2\theta}}$$

• We have a sign difference, but I think it just comes from me playing with inequalities. – zeldredge Apr 10 '15 at 21:47
• @zeldredge yeah, I didn't notice you answer. sorry. I guess we were answering the question at the same time. and yeah for the sign, since it is going to be used in that situation, I assumed the negative sign is not needed. and also I asked him in the comment, do you need the minimum velocity, and he said yes, So I didn't use an inequality. ;) – Mobin Apr 10 '15 at 21:56
• Well, I actually had an $L$ and not an $L^2$ until you posted your answer, so thanks for helping me check units :p – zeldredge Apr 10 '15 at 21:57
• @zeldredge ;) ;) – Mobin Apr 10 '15 at 21:58
• @StepTNT Removing error is always the nasty part in these projects. the thing you have to do is to multiply a number to velocity like 0.8 to make it more real. the problem is that the lower velocity's will be less accurate then. you have to put if statement , and divide your results. for example if the velocity was between 100 and 80, then the velocity will be 0.8 . if you want it to be more smooth you have to make this multiplier a function. measure the error in each velocity and take the variance from it. then multiply the result on 1/variance. search the Google for more methods.take care ;) – Mobin Apr 12 '15 at 14:38

If you have initial velocity $v_0$ and initial launch angle $\theta$ (assumed $0 < \theta < \pi/2$), after a time $t$ you will have traveled through a distance: $$\Delta x = v_x t = v_0 \cos \theta \\ \Delta y = - \frac{1}{2} g t^2 + v_y t = - \frac{1}{2} g t^2 + v_0 \sin \theta$$ The time required to traverse distance $L$ is the time you need to be in the air for: $$t = \frac{L}{v_0 \cos \theta}$$ After this time we want our $\Delta y$ to be $h$ or better: $$h < - \frac{1}{2} g \frac{L^2}{v_0^2 \cos^2 \theta} + \frac{L v_0 \sin \theta}{v_0\cos \theta}\\ <- \frac{1}{2} g \frac{L^2}{v_0^2 \cos^2 \theta} + L \tan \theta$$ Solve the inequality for $v_0^2$: $$-\frac{1}{2} g \frac{L^2}{v_0^2 \cos^2 \theta} > h - L \tan \theta \\ v_0^2 > \frac{1}{2} g \frac{L^2}{( h - L \tan \theta) \cos^2 \theta}\\ v_0 > \sqrt{\frac{g L^2}{2 ( h - L \tan \theta) \cos^2 \theta}}$$ You, of course, want the positive root. Note that this also tells you when the problem is impossible: if $L \tan \theta > h$, then the straight-line path you get without falling at all isn't even enough to get you to the other ramp.

• Comment: this is basically the first physics lab I ever did in high school, with a spring-loaded ball bearing launcher. It holds a very special place in my heart. – zeldredge Apr 10 '15 at 21:59
• This is a though choice because you both replied with the same answer in the same time and I'd like to accept both of them but I can't. I edited the question with a little new issue tho :) – StepTNT Apr 12 '15 at 9:41