# Determining if my target is standing upright

 0 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, more ▼ asked Dec 05 '10 at 11:59 PM BigToe 35 ● 5 ● 6 ● 12 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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.) more ▼ answered Dec 06 '10 at 02:51 AM Jesse Anders 7.3k ● 7 ● 17 ● 48 Thanks. I completely forgot about the transform.up for some reason. i'll put my code below. Dec 06 '10 at 08:25 AM BigToe add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 This is what I ended up using after Jesse reminded me of the transform.up vector. ``````if (transform.up.y < .6f){ // code here } `````` more ▼ answered Dec 06 '10 at 08:26 AM BigToe 35 ● 5 ● 6 ● 12 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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. more ▼ answered Dec 06 '10 at 12:23 AM BigToe 35 ● 5 ● 6 ● 12 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2159
x1865
x439
x286
x55

asked: Dec 05 '10 at 11:59 PM

Seen: 975 times

Last Updated: Dec 06 '10 at 12:24 AM