Reputation: 17
I'm having a little bit of trouble, I created a tree for 3 different animations to move forward or forward Left/Forward Right, now the only animation working is the moving forward, transitioning to moving left or right/changing the horizontal value does not affect the animation to change, why is that? Animator
For reference I was trying to achieve this here: https://www.youtube.com/watch?v=U0dlWhB_e0E
The idle animation is working fine, when I press W it switches to walking animation perfectly, now pressing S/D/A does not change the animation to walking left/right animation which I already included in the animator
Here's also the movement script for the character
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
public Animator anim;
// Update is called once per frame
void Update()
{
anim.SetFloat("vertical", Input.GetAxis("Vertical"));
anim.SetFloat("horizontal", Input.GetAxis("Horizontal"));
if (controller.isGrounded)
{
velocity.y = 0;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}```
Upvotes: 0
Views: 870
Reputation: 17
So with some help it turns out I had to make the blend tree in 2D freeform mode and to apply all animations in the same blend tree applying different values to each one and then the horizontal and vertical parameters helped, thanks for the help!
Upvotes: 0
Reputation: 23
Your animator is missing the "forward left"/"forward right" animations. You just added "idle" and "Movement". Maybe you think that "Movement" includes all tree animations to move forward. But it only holds the animation to move forward.
Drag and drop the two missing animation assets into your animator window to add them. Then you can add the transition conditions to them like you did with the "idle" and "Movement" animations.
Upvotes: 0