- Home /
I have a value that determines which way my character is facing in degrees. How do I convert that value to a range of -1 to 1 for smooth mecanim bleend tree animation?
My game is a top down shooter. The direction value is zero degrees when my player is facing the same direction that he is walking. It's around 90 degrees when he is moving left but facing forward. It's around 270 when he's facing forward but moving right. And about 180 when he's walking backward.
The value is clamped so 370 wraps around to 10. Which means the 340ish to 20 degree area is pretty much straight forward. This is the cause of my problem in mecanim.
I have 4 anims. Run forward, and strafe left/right/back. In the blend tree if I set the threshold of run forward to be 0, and the threshold of strafe right to be 270. The anim we'll abruptly switch from strafe right to run forward once the 360 rolls over to zero. So how can I convert this degree system into a range where lets say -1 is strafe left, 0 is forward, and 1 is right? (I'd have to figure out how to get the backwards anim some other way but I have a few ideas for this).
Math.DeltaAngle was very promising but it only works if he's facing north. It plays the wrong anims if he's facing any other cardinal direction. Maybe this is due to my input? I'm using the same direction value and another variable that I've named moveAngle. moveAngle is simply 0 (degreess) when he moves north (player is pressing W). 90 for east, -90 for west and 180 for south. Math isn't my strong suit so any help would be appreciated!