Question by
AskYri · Nov 29, 2019 at 03:23 PM ·
animationbugvelocitylocal velocity
Getting player's local direction
I'm trying to get the player's velocity to drive the player's walk and run animations. I use this code to get the local velocity and it works, but the localDir value jumps a lot in-game, causing the player's animations to be janky as the transition between walking and running is based on that.
void PlayerLocalDireciton()
{
dir = (player.transform.position - lastPos);
localDir = player.transform.InverseTransformDirection(dir);
localDir = Vector3.Scale(localDir, new Vector3(scale, scale, scale));
localDir.x = Mathf.Clamp(localDir.x, 0f, 1f);
localDir.z = Mathf.Clamp(localDir.z, 0f, 1f);
lastPos = player.transform.position;
animator.SetFloat("Vertical", localDir.z);
animator.SetFloat("Horizontal", localDir.x);
}
Comment
Your answer
Follow this Question
Related Questions
Animation tab not working properly 0 Answers
How to make soccer ball spin according to its velocity in 2D top down game 0 Answers
Why my object disappear in some frame in this animation ? 0 Answers
Offset position in animation of animator when it plays 1 Answer
Animations unwanted movement and rotation after updating 0 Answers