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).
EDIT:
Based on @mklingen here's the C#
code that I'm using (where Distance = L
)
var speed = (Mathf.Sqrt(g)*Mathf.Sqrt(Distance)*Mathf.Sqrt((1/Mathf.Sin(Theta)))* Mathf.Sqrt((1/Mathf.Cos(Theta))))/Mathf.Sqrt(2);
What happens is quite weird though.
For example, with theta = 19, L = 196, h = 46
my code returns 80.54646
which seems to work if I input it to the car. However running the expression in WolframAlpha leads to 55.8
which is wrong.
It may seem that the code is correct but with theta = 35, L = 261, h = 39
my code returns NaN
while WolframAlpha shows 52.17
which made the jump happen.
So, tu summarize, I have 2 different cases in which my result is different from WolframAlpha's one and none of them is the correct one both the times.
What's going on?
57.29578
in Wolfram) and now they both return the same values for the first case. The problem still remains for the second one: now Wolfram returns-57.4
(which is clearly wrong) while my code still returnsNaN
. So, what happens is that if I change the expression into degrees than the first case is solved, if I change my code into radians than I can solve the second one but I can't solve them together. \$\endgroup\$