I'm new to Unity and after doing some tutorials and reading documentation from Unity, I've started a test project. The game is a 2.5D platformer and I wrote the PlayerController; it looks like this:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float turnSmoothing = 15f;
public float speedDampTime = 0.1f;
private Animator anim;
private Rigidbody rb;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
anim.SetLayerWeight(1, 1f);
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
MovementManagement(h);
}
void MovementManagement (float horizontal)
{
if (horizontal != 0.0f)
{
anim.SetBool("Move", true);
anim.SetFloat("Speed", 5.5f, speedDampTime, Time.deltaTime);
Rotating(horizontal);
}
else
{
anim.SetFloat("Speed", 0.0f);
anim.SetBool("Move", false);
}
}
void Rotating (float horizontal)
{
Vector3 targetDirection = new Vector3(horizontal, 0.0f, 0.0f);
Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
Quaternion newRotation = Quaternion.Lerp(rb.rotation, targetRotation, turnSmoothing * Time.deltaTime);
rb.MoveRotation(newRotation);
}
}
My AnimatorController has a BlendTree called Locomotion and looks like this:
When I run the game and use the keyboard or the controller the player starts walking, but it takes a long time (I can see the Speed parameter from the blend Tree that has to reach "5" to start walking)
I think I'm not understanding something but I don't know what it is.