Like others, I also had some odd issues with the IsStanding code. Part of it is that I’m using garden gnomes (which has been a hassle), and they had slightly different rotations. While noticing that angles were never 0, I found this nice little function:
MathF.DeltaAngle(angle1, angle2).
DeltaAngle returns the difference between two angles. It takes care of negatives, wrap around 360, etc. So, I just used 0 as the angle to compare against (the original code could use 270 I guess). So, with my gnomes (different model) here’s the code:
public bool IsStanding () {
Vector3 rotationInEuler = transform.rotation.eulerAngles;
//jdg: note this is called every tick
float tiltInX = Mathf.DeltaAngle(rotationInEuler.x,0);
float tiltInZ = Mathf.DeltaAngle(rotationInEuler.z,0);
if ((tiltInX < standingThreshold) && (tiltInZ < standingThreshold))
{
return true;
}
else
{
return false;
}
}
== John ==