I am new to unity and I am starting out by making a simple level in which you walk around in in first and third person. I am trying to animate the characters idle and walking am having trouble. Everything works fine including the transition from idle to walk until I change the exit time float to a speed float. I added the speed float and ordered it to transition from idle to walk if the speed is greater than 0.1. When I do that and play the walking animation never happens and I glide around in the idle animation. Does anyone know what I can change to fix this problem?
You have to forward the current speed/velocity to your Animator speed value. Get the Animator on Start or set a reference to the public member.
public Animator mAnimator;
Rigidbody mBody;
void Start()
{
mBody = GetComponent<Rigidbody>();
}
void Update()
{
mAnimator.SetFloat("MySpeed", mBody.velocity.magnitude);
}
I assume the problem is that you are not setting the speed value anywhere. A simple way to do that would be to code a script that access the animator’s speed variable.
GetComponent<Animator>().SetFloat("Speed", 1);
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
float speed = 10f;
Vector3 direction = Vector3.zero;
CharacterController cc;
// Use this for initialization
void Start () {
cc = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
direction = transform.rotation * new Vector3( Input.GetAxis ("Horizontal") , 0, Input.GetAxis ("Vertical") ).normalized;
}
void FixedUpdate () {
cc.SimpleMove(direction * speed);
}
}
This is my player movement script. Can you edit my code to get it to do what you’re saying?