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\$
1
  • \$\begingroup\$ Could you clarify which dimensions the car is rolling in? A screenshot with the transform axes displayed could be useful. \$\endgroup\$ Commented Dec 31, 2019 at 13:51

2 Answers 2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .