Skip to main content
deleted 9 characters in body
Source Link
wondra
  • 4.9k
  • 1
  • 23
  • 36

I would not complicate things much:

public bool IsUpright () {
        return transform.rotation.up.y > threshold;/*say 0.6 ?*/
}

because the up vector is normalized and, naturally, points upwards you just need to check its length in Y axis(or the "up" axis if you use different one). It will be 1.0 when perfectly up and -1.0 if perfectly upside down. This simple code will suffice - if you don't require exact angle, of-course(you can still compute the equivalent Y threshold value of angle should you require it).

I would not complicate things much:

public bool IsUpright () {
        return transform.rotation.up.y > threshold;/*say 0.6 ?*/
}

because the up vector is normalized and, naturally, points upwards you just need to check its length in Y axis(or the "up" axis if you use different one). It will be 1.0 when perfectly up and -1.0 if perfectly upside down. This simple code will suffice - if you don't require exact angle, of-course(you can still compute the equivalent Y threshold value of angle should you require it).

I would not complicate things much:

public bool IsUpright () {
        return transform.up.y > threshold;/*say 0.6 ?*/
}

because the up vector is normalized and, naturally, points upwards you just need to check its length in Y axis(or the "up" axis if you use different one). It will be 1.0 when perfectly up and -1.0 if perfectly upside down. This simple code will suffice - if you don't require exact angle, of-course(you can still compute the equivalent Y threshold value of angle should you require it).

Source Link
wondra
  • 4.9k
  • 1
  • 23
  • 36

I would not complicate things much:

public bool IsUpright () {
        return transform.rotation.up.y > threshold;/*say 0.6 ?*/
}

because the up vector is normalized and, naturally, points upwards you just need to check its length in Y axis(or the "up" axis if you use different one). It will be 1.0 when perfectly up and -1.0 if perfectly upside down. This simple code will suffice - if you don't require exact angle, of-course(you can still compute the equivalent Y threshold value of angle should you require it).