This is related to my previous post in the animation section, but my issue is related to code so this post was in the wrong forum (Adjusting blend tree parameters based on 3 dimensions (horizontal, vertical and rotation). - Unity Engine - Unity Discussions).
I have a rather complex problem with 2d animation blend trees that is doing my head in.
I am building a rather simple top down isometric style game, similar to the “Survival shooter” tutorial by the Unity guys.
The main difference I have at this stage, is that I am using more complex humanoid character models that have movement animations for 8 degrees. I have built a blend tree for this that operates on the Horizontal and Vertical input (WASD)… this works great (see attachment).
However, the player (and other game characters) can be facing/aiming in any direction within 360 degrees, while moving in any direction within 360 degrees.
So if the player is facing 0 degrees and hits the W key he correctly moves and visually appears to be moving forward… however if the player is facing 180 degrees and presses W, he is now correctly moving backwards but he still appears to be moving forwards.
It’s a little difficult to explain, but I hope this is clear?
I have come to the conclusion that this needs to be handled in code, so effectively the only way that is clear to me is to apply a modifier to the horizontal and vertical output to flip the output based on direction of angle.
Here is a rough code example of what I need:
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
float direction = Quaternion.LookRotation(rigidBody.transform.forward).eulerAngles.y
// psuedo code just to demonstrate problem
if (direction > 0 && direction < 180)
{
v = v-1; //flip the axis value
}
animatorController.SetFloat ("Horizontal", h);
animatorController.SetFloat ("Vertical", v);
I’m totally stuck here, please help!