Simpler Method to detect if a pin is standin up

I was unable to get proper results using euler angles to determine if a pin is standing up. I have reached another solution.

I compare the local space up vector(expressed in world coordinates) with the world space up vector in order to get the angle betwen this two vectors. Here is the code:

    public bool IsStanding() {
        //pinAngle is the angle betwen local space up vector and world space up vector 
        float pinAngle = Vector3.Angle(gameObject.transform.up, Vector3.up);
        //standingThreshold is the maximum angle to determine if 
        //a pin is pointing up enough to consider it standing
        if (pinAngle>standignThreshold) {return false;}
        return true;
    }

At this moment it works perfectly. I can not determine if this method is too much time consuming or not, but for now it works perfectly.

1 Like

After a night of trying to wrap my head around the other thread talking about Quaternions, I came back to this one.

This seems to make so much sense, and works perfect for me too. Maybe the Quaternion solution would be less CPU-heavy, but I wouldn’t know at this point.

Privacy & Terms