How to check if an object is upside-down?

I am making a racing game, and I need to be able to check if a player or AI car is flipped upside down. I have tried using the vehicle’s X and Z euler angles to check, but it is not working very well because the values jump due to the obvious problem of gimbal lock. Does anyone know of a way to check using Quaternions?

1 Like

Something like

if (Vector3.Dot(transform.up, Vector3.down) > 0)
// car's up-vector has a down facing component

The dot product is greater than 0 if the car’s roof is pointing even slightly downward and it equals 1 when the cars up-vector points to the same direction as Vector3.down (totally upside down). It’s also a very fast calculation.

You could find a value between 0 and 1 that works well for you.