- Home /
Negative parameters in mecanim blend tree not animating
Hello!
Background
I'm making a top-down 2.5d game where the player character looks towards the cursor at all times and the WASD keys move the character up, left, down, and right irrespective of the player's rotation. To accommodate this in animation, I used a 2D blend tree to blend a few animations from Mixamo. The problem I've run into, though is that when the character needs to move backwards, the animation freezes.
Details
To accommodate this in animation, I built the following blend tree to blend movement:
When I play with the parameters in the animator window, everything runs smoothly in the Inspector preview.
In order to figure out how much the player is moving forward and sideways relative to the cursor, I use the following code:
float moveAngle = (Vector2.Angle(Vector2.right, movement) * Mathf.Sign(movement.y) - Body.rotation) % 360;
float forward = Mathf.Cos(Mathf.Deg2Rad * moveAngle);
float sideways = Mathf.Sin(Mathf.Deg2Rad * moveAngle);
Anim.SetFloat("forward", forward);
Anim.SetFloat("sideways", sideways);
(Where "movement" is a Vector2 with its x being "Input.GetAxisRaw("Horizontal")" and its y being "Input.GetAxisRaw("Vertical")". Body refers to the Rigidbody2D component of the gameobject.)
I've used Debug.Log to check the output of each part of the process, and it all matches up with what I've expected. Nevertheless, whenever the "forward" or "sideways" parameter is negative in testing, the animation freezes (which, again, does not occur in the preview window).
I've tested this by going directly towards and away from the cursor at a number of angles and directions, as well as circling (more like squaring, really) the cursor, which is the most interesting because the animation plays until during each movement across the side of the square, the cursor is crossed, at which point it freezes.
Any help would be super appreciated. If what I'm describing doesn't make much sense, I'll try to see what I can do about getting a video or something up. Thank you!
its old but im getting same problem blendtree in inspector works fine but with same value through code it behave very strange (its negative value ) what is goinnn onnn !!