- Home /
How to unflip a car?
For my car I have a ridged body, box collider, four wheel colliders and a movement script. It works pretty well for the most part but when I drive off a ramp or bumpy terrain it will roll over and sometimes land on its side or back. I want it to automatically correct its position when it does that, how can I do this?
Hi, were you ever able to figure out a solution for this?
Answer by Llama_w_2Ls · Dec 08, 2020 at 04:03 PM
Even though the OG has probably moved on, I'll try my best to answer the solution with a set of methods:
1. Rotate the car
Normally, the car should be upright when the x and y axis rotation is equal to 0. The z-rotation should remain the same, as to keep the direction the car was initially facing.
You can do this by setting the transform.rotation of the car. E.g:
void Unflip()
{
Car.transform.rotation = new Vector3(0, 0, Car.transform.rotation.z);
}
You can have a smoothing value so that it doesn't just teleport to an unflipped position, but slowly rotates itself, maintaining the physics.
2. Adding Force
By adding a force to stabilise the car, you can unflip it in a much smoother and controlled manner, than by manually setting the rotation.
To calculate the direction and magnitude to apply the force, you might need to do some testing. Adding a force upwards to the Car with a slight incline, will cause it to tip. The magnitude will be dependant on how large the flip was. If it's totally upside down (on its back), the magnitude will be great. If it's just on its side, a little nudge in the right direction should do the trick. Preferably applied to the top of the car.
Your answer
Follow this Question
Related Questions
Setting Wheelcollider BrakeTorque to 0 does not release brake 0 Answers
Car Movment Script not fully working!!!!!!! 1 Answer
My simple car leans INTO the turn, and leans over on two wheels. 1 Answer
Strange behavior with the Unity car? 0 Answers
Car speed physics problem, accelerates and turns out of controll 0 Answers