# Determining if my target is standing upright

What is the best way to determine if my target is standing upright after it has been hit with a physics force?

I would like to be able to have a threshold value if the target is leaning. If it is leaning say 45 degrees or less, it is still considered upright.

Thanks,

Don't use Euler angles for this. Instead, check the object's local 'up' vector to see how 'upright' it is. (An easy way to do this would be to compare the local up vector's 'y' value - assuming y is up - to some threshold value, e.g. .7. If you want to express the threshold in terms of an angle, you can compute the threshold for the y value from that angle using trig.)

This is what I ended up using after Jesse reminded me of the transform.up vector.

``````if (transform.up.y < .6f){
// code here
}

``````

Don't know if this is the correct way to do it, but it seems to work.

Basically look at the eular angles. If the angle is greater than 45, then I considered the target knocked down.

``````if (360 - Mathf.Abs(transform.eulerAngles.x - 360) > 45 || 360 - Mathf.Abs(transform.eulerAngles.z - 360) > 45)
{
//The target is knocked over.  Do what you please.
}

``````

I'm guessing there may be a more elegant way.

nice! it worked for me, I was using eulerAngle, but it do not work properly: