0
\$\begingroup\$

I have a standart Unity car with Unity Car physics. What would be the best approach to protect my car from a rollover?

I dont want to mess up and try and error 10 different approaches, so maybe here is an expert who really knows how to do it right?

I couldnt find anything decent on the internet.

\$\endgroup\$
  • \$\begingroup\$ Could you clarify which dimensions the car is rolling in? A screenshot with the transform axes displayed could be useful. \$\endgroup\$ – disc_code22 Dec 31 '19 at 13:51
1
\$\begingroup\$

Ideally use AddRelativeTorque. In its simplest form, flip the car on its Z axis when the car is upside down.

RigidBody RB = ...;
float flipStrength = 1f;

if (Mathf.Abs(transform.localRotation.eulerAngles.z) > 90f) {
    RB.AddRelativeTorque(0f, 0f, flipStrength, ForceMode.Acceleration);
}
\$\endgroup\$
0
\$\begingroup\$

Quick and dirty: Just lock the x and z axis of the rigidbody. Now the car will always stay horizontal. But it also will have difficulties with ramps.

\$\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.