- Home /
Question by
artwen · Dec 04, 2017 at 05:27 AM ·
angleboxcollidercentercenterofmassflat
How do I know if a cube is lying flat on the ground? (the quickest way)
I have a scene where boxes (with rigidbody) are scattered around the ground. As the ground is not totally flat, some of them is lying flat when the others are titling (lying or leaning on underneath stones of random sizes).
I want to know if a box is lying flat on ground (otherwise I'll roll the box to a flat area of ground). Currently I'm doing an angle check(Vector3.Angle(axis, Vector3.up)) with axis being all 6 axis of the box (box.transform.up, -box.transform.up, box.transform.forward, etc.), and if the smallest angle is not 0, then box is not lying flat on ground.
Is there any other better way to achieve this? (e.g. using the box's BoxCollider.center or Rigidbody.centerOfMass or something alike)
Comment