Animation with different behaviors for different directions.

When I press down, the animation correctly changes to go down, when I press down together with left or right, the character moves to the respective diagonal and the animation continues to go down, which is the result that I want. But … When I’m pressing left and down for example, it moves on the respective diagonal, but the animation changes to go down instead of keeping the animation to the left, when I’m pressing left and up, the animation doesn’t change, which is a very strange behavior.

I know what is causing this problem, when I change the order in which I am assigning the parameters in the animator, the behavior is the opposite. but I’m not being able to solve it.


110880-asdasdada.png

here’s a video I made to you guys see what’s going on.

And here’s my movement script.

//Components
	private Rigidbody2D rb2d;
	private Animator anim;
	
	//Movement
	private Vector2 movement;
	private Vector2 movementVector;
	//private Vector3 directionVector;
	private Vector2 facing;
	private bool CanMove;
    
	//Speed Modifier
	public float speed;
	
	// Use this for initialization
	void Start ()
	{
		//getting the components
		rb2d = GetComponent<Rigidbody2D>();
		anim = GetComponent<Animator>();
		CanMove = true;
	}
	
	// Update is called once per frame
	void Update () 
	{
		//getting the axis
		movementVector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
		//directionVector = Camera.main.ScreenToViewportPoint(Input.mousePosition);
		
		//seeing if the the character is moving
		var isMoving = ((Mathf.Abs(movementVector.x) + Mathf.Abs(movementVector.y)) > 0);
		
		
		if (isMoving)
		{
			if(!CanMove)
				return;
			
			//calculating the movement
			movement = (movementVector * speed);
			
			//setting the isMoving to true
			anim.SetBool("isMoving", true);
			
			//calculating the facing direction
			facing = rb2d.velocity.normalized;
			
			//anim.SetFloat("moveX", directionVector.x);
			//anim.SetFloat("moveY", directionVector.y);
			
			//setting the movement variable with the movementVector
			anim.SetFloat("moveX", movementVector.x);
			anim.SetFloat("moveY", movementVector.y);
		}
		else
		{
			//if isn't moving, assign the facing parameter
			anim.SetFloat("facingX", facing.x);
			anim.SetFloat("facingY", facing.y);
			
			//stop the movement
			movement = Vector2.zero;
			//set the isMoving to False
			anim.SetBool("isMoving", false);
		}
		
		
	}

	void FixedUpdate()
	{
		//apply the movement
		rb2d.velocity = movement;
	}

I’m not sure what is the solution, so probably the blend state settings have some issue, for example it does not allow blending the variables, or it activates a wrong state (maybe both movement left and right activate, but in reverse proportions).

The code looks fine, and you did mention that changing the order reverses the behaviour.

One last idea: what happens if you put anim.SetBool("isMoving", true); after you assign the animation parameters?