x


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,

more ▼

asked Dec 05 '10 at 11:59 PM

BigToe gravatar image

BigToe
35 5 6 12

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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 gravatar image

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
(comments are locked)
10|3000 characters needed characters left

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 gravatar image

BigToe
35 5 6 12

(comments are locked)
10|3000 characters needed characters left

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 gravatar image

BigToe
35 5 6 12

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

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