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,
Answer by Jesse Anders · Dec 06, 2010 at 02:51 AM
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.)
Thanks. I completely forgot about the transform.up for some reason. i'll put my code below.
Answer by BigToe · Dec 06, 2010 at 08:26 AM
This is what I ended up using after Jesse reminded me of the transform.up vector.
if (transform.up.y < .6f){
// code here
}
Answer by BigToe · Dec 06, 2010 at 12:23 AM
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.
Answer by diegodimap · Aug 23, 2017 at 01:25 PM
nice! it worked for me, I was using eulerAngle, but it do not work properly:
[1]: /storage/temp/100482-standing.png