- Home /
How do I fix this lerp this float so it doesnt snap from animation to another
Im trying to get these animations to play smoothly but I cant get it to not snap between animations because the code changes the float to fast. I need it to basically lerp the variable.
here is my code using UnityEngine; using System.Collections;
public class MoveAround : MonoBehaviour {
public Animator anim;
public float rotationSpeed = 1;
public float lerp = 0.1f;
public float rotatsada;
void Update ()
{
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
float speed = Input.GetAxis("Vertical");
float rot = rotation;
float sped = speed;
float lerpRot = Mathf.Lerp(rot,rotation, 0.1f);
float lerpSpeed = Mathf.Lerp(sped,speed, 0.1f);
rotatsada = lerpRot;
if(Input.anyKey && !Input.GetKey(KeyCode.Mouse0))
{
if(Input.GetKey(KeyCode.LeftShift))
{
anim.SetFloat("Speed", lerpSpeed);
}
else
{
anim.SetFloat("Speed", lerpSpeed * 0.5f);
}
anim.SetFloat("Direction", lerpRot);
}
}
}
Comment
Best Answer
Answer by jenci1990 · Dec 13, 2014 at 08:05 AM
You do this:
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
float speed = Input.GetAxis("Vertical");
float rot = rotation;
float sped = speed;
But rotation equal to rot. Try this:
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
float speed = Input.GetAxis("Vertical");
float rot = anim.GetFloat("Direction");
float sped = anim.GetFloat("Speed");
Your answer
Follow this Question
Related Questions
What is the proper way to wait for an Animator Controller to update? 1 Answer
Create 2D box colliders based on current frame of animation 0 Answers
Trigger Activated Multiple Times From One Click 2 Answers
Player movement starts after a few seconds after pressing the button 1 Answer
How to maintain FIFO in Animator controller when you set multiple parameter in one frame ? 0 Answers