So I am currently having a problem with my Animation controller, dealing with one of the blend trees to make the character walk.
It looks like this:
So, inside the blend tree I have all the different walking animations that uses the floats “Walk Type X”, and “Walk Type Y” for blending the between the animations.
But the problem I am having is when walking forward, the animation just freezes, same when walking backwards.
Here is the code for the script controlling the animations:
using UnityEngine;
using System.Collections;
public class PlayerAnimatorScript : MonoBehaviour
{
public GameObject playerModel;
private float walkTypeXCurrent;
private float walkTypeXTarget;
private float walkTypeYCurrent;
private float walkTypeYTarget;
private float changeVelocityX;
private float changeVelocityY;
private bool jumping = false;
private bool inAir = false;
private InputScript inputScript;
private PlayerMovementController playerMovementController;
private Animator animator;
void Update()
{
if (inputScript == null)
{
inputScript = transform.GetComponent<InputScript>();
}
if ((inputScript != null)&&(playerMovementController == null))
{
playerMovementController = transform.GetComponent<PlayerMovementController>();
}
if (playerModel != null)
{
animator = playerModel.GetComponent<Animator>();
}
print (animator.GetBool("Moving"));
walkTypeXCurrent = Mathf.SmoothDamp(walkTypeXCurrent, walkTypeXTarget, ref changeVelocityX, playerMovementController.speedUpTime);
walkTypeYCurrent = Mathf.SmoothDamp(walkTypeYCurrent, walkTypeYTarget, ref changeVelocityY, playerMovementController.speedUpTime);
animator.SetFloat ("Walk Type X", walkTypeXCurrent);
animator.SetFloat ("Walk Type Y", walkTypeYCurrent);
//THIS SECTION TAKES IN MOVEMENT
if ((animator != null)&&(playerModel != null))
{
if (jumping == false)
{
animator.SetBool ("Jumping", false);
if ((inputScript.forwardInputPressed)||(inputScript.backwardInputPressed)||(inputScript.leftInputPressed)||(inputScript.rightInputPressed))
{
animator.SetBool ("Moving", true);
walkTypeXTarget = 0;
walkTypeYTarget = 0;
if ((inputScript.forwardInputPressed)&&(!inputScript.backwardInputPressed))
{
++walkTypeYTarget;
}
if ((inputScript.backwardInputPressed)&&(!inputScript.forwardInputPressed))
{
--walkTypeYTarget;
}
if ((inputScript.leftInputPressed)&&(!inputScript.rightInputPressed))
{
++walkTypeXTarget;
}
if ((inputScript.rightInputPressed)&&(!inputScript.leftInputPressed))
{
--walkTypeXTarget;
}
}
else
{
walkTypeXTarget = 0;
walkTypeYTarget = 0;
if ((walkTypeXCurrent <= 0.1)&&(walkTypeYCurrent <= 0.1))
{
animator.SetBool ("Moving", false);
}
}
}
else
{
animator.SetBool ("Jumping", true);
}
}
}
}
And to show the problem more accurately, here is a video of it:
Anyone have any idea how to fix this, or even what the problem is? I’m actually starting to think its a bug with Mecanim itself.