I only know how to do it when the camera's Y rotation is set to 0.
This's what I did:
void GetDirection () {
float headingAngle = transform.rotation.eulerAngles.y;
if (headingAngle > 315 || headingAngle < 45)
anim.SetBool("GoForward",true);
else if (headingAngle < 225)
anim.SetBool("GoLeft",true);
else if (headingAngle < 135)
anim.SetBool("GoBackward",true);
else
anim.SetBool("GoRight",true);
}
However this won't work when camera rotates, since the "forward angle" is not 0. I seriously don't know how to the angle calculation when the angle goes over 360.
↧