Determine object's tipping point.
Hi all,
Unity noob here, with a question that seems like it should have a simple answer. I'd like to determine the tipping point of an object (rigidbody). Take a cube at rest on a plane, and apply a torque to it around the X or Z axis. At some point (the TP) it will tip over - this happens in real life when the center of mass of an object falls outside its base. I'd like to know the specific moment this happens, for arbitrary objects.
I've tried messing with transform.up and friends, but it seems like I'd have to calculate a specific threshold of 'tippiness' for any given object in advance. Quite clearly the physics engine knows when an object tips over, so it seems reasonable enough to expect to be able to retrieve the information.
Methods attempted:
Compare transform.up to Vector3.up. If some threshold exceeded, the object is tipped. Works, but has to be tweaked for different objects in advance. I'd like to be able to calculate on a per-frame basis (e.g. in Update())
Similarly, compare angular velocity against some threshold. This had less than satisfying results, since an object can wobble considerably before finally settling back to its original position.
Retrieve the object's renderer bounds, and attempt to determine if the X or Z coordinate of the center of mass differs from those of the base (the corner coordinates, in the case of a cube). This involved a lot of vector3 math, leading me to believe I'm on the wrong path, and also doesn't work in any case since the bounds of an object are axis-aligned to the world and always contain the object's center of mass (unless CoM is tweaked to be "outside the object" - but that would not be realistic) . Even if it worked for a cube, it seems unlikely to work for any given arbitrary structure.
Calculate a non-AABB bounding box based on the transform's position and rotation, and apply vector math similarly to 3. Again, seems like a lot of work for something that should be exposed in an API* somewhere, and also would be hard to achieve consistent results across arbitrary structures.
*Ideally, something like transform.bounds.Contains(rigidbody.centerOfMass.position)
So what am I missing?
I've also added method 5:
Raycast from the C-of-$$anonymous$$ vertically down (
-Vector3.up) and see if this intersects the base of the object. This seems to be the most promising approach so far, although I have no idea how to deter$$anonymous$$e if such a ray passes through the base. Can't use a bounding box approach for the reasons above, and there doesn't see to be anArbitraryGeometry.IntersectRay()method anywhere.
Your answer