- Home /
Why can't my car jump off of ramps in a realistic fashion?
I'm working on a simple racing game, and I love the way my car handles while driving on flat surfaces. The problem is that whenever it hits a bump in the road or reaches the end of a hill, the car gets tossed into the sky. It's a bit hard to explain, but it seems like the physics engine thinks the car is driving at a higher speed than it is, so that when it gets airborne it flies way too far. Anyone got any idea how to fix this? I want the car to be able to jump off of ramps in a realistic fashion, but at the moment this just doesn't work...
You'll probably have to give more detail about how you have your car set up. For instance, are you using wheel colliders? Can you provide a link to a webplayer example?
I can't provide a link to a webplayer example, sorry, but I can go a bit more in detail on my setup. I use wheel colliders, and my car has a low center of gravity. The suspension-thingys are quite long, but I don't remember the exact details. I have the project on another machine, and won't use it until tomorrow, but I can add a more accurate post when I wake up.
I used the script from Andrew Gotow's car tutorial (http://www.gotow.net/andrew/blog/?page_id=78) as reference for my car script and added some code of my own to get better handling. I don't think the problem lies in my own code...
Answer by efge · Jan 19, 2010 at 05:18 PM
Started with the same setup from Andrew Gotow's blog and run into similar problems.
After reading Flashbang Studios' Unite article I switched to a setup with Raycast Colliders and now it works.
http://unity3d.com/support/resources/unite-presentations/physics-the-right-way
Answer by runevision · Dec 22, 2009 at 09:47 AM
If the car has the right speed and angle when leaving the ramp, but flies way too far when it is airborne, maybe the gravity is set too low? Generally, gravity is the only setting affecting how fast objects fall to the ground, unless you have some really extreme air resistance settings, or other forces are affecting the car.
The scale of the scene also matters. If gravity is set to a realistic value but the scene isn't using the proper scale (1 unity unity = 1m) then that also will look unrealistic.
There is not one "correct scale". Units in Unity can represent anything you want. The gravity should be set up to be realistic (if that is desired) for the given scale that is used. So if for example the scene uses (1 Unity unit = 1 cm) then the gravity vector must be specified in cm too.
in fact, changing the gravity only seems to affect the speed of the fall, not the length...
That should definitely not be true in the general case. Since increased gravity makes it goes downwards faster but doesn't go forward faster, it should hit the ground after a shorter distance. There must be something very specific about your setup...
I think the problem might have to do with the gears of my car. I would like to hinder the car from changing gears while airborne, but I don't know how to check if the car touches the ground or not. Any advice? Should I use GetGroundHit or something? $$anonymous$$aybe I'm stupid now, but I'm kind of a newbie...