2
\$\begingroup\$

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.

physics problem

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?

\$\endgroup\$
  • \$\begingroup\$ It sounds like your system and wolfram are using different angle units. \$\endgroup\$ – Seth Battin Apr 10 '15 at 20:17
  • \$\begingroup\$ You're correct, the expression was written in radians while my data was in degrees. I changed the expression to match degrees (just multiplied angles by 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 returns NaN. 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\$ – StepTNT Apr 10 '15 at 20:48
  • \$\begingroup\$ You may want to try math exchange or physics \$\endgroup\$ – Evorlor Apr 10 '15 at 21:01
0
\$\begingroup\$

I solved it using kinematics but got a much more complex equation than what you have already.. I think it should work, and I've double-checked the math (and did a bunch of it using wolfram), but I'm wary of it just because of how long the equation came out to be.

where y = the height of the second ramp - the end height of the first ramp, and g is positive

See solution at wolframalpha.com

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.