AlpakaJoe
AlpakaJoe

Reputation: 593

Unity: How to check if Capsule is fallen?

I have 10 Capsules in my game.

I want to check if those Capsules are standing like they do when the game starts, or if they are fallen down (laying on the ground).

What i would need is:

But i don't know how to do that?!

Upvotes: 1

Views: 59

Answers (1)

Ruzihm
Ruzihm

Reputation: 20269

Use Vector3.Angle(gameObject.transform.up, Vector3.up)

Compare the output of Vector3.Angle(gameObject.transform.up, Vector3.up) to a limit, and see if the angle exceeds (or meets?) that limit.

GameObject gameObject; // given
float angleLimit;      // given - measured in degrees
float upAngle = Vector3.Angle(gameObject.transform.up, Vector3.up);
if (upAngle >= angleLimit) {
    // gameObject is not upright
}

Upvotes: 1

Related Questions