- Home /
Set walk animation speed to velocity
How should I set a character's walking animation speed to their movement speed?
I got the velocity quite easily — velocity = (transform.position - lastPosition) / Time.deltaTime;
Should I use velocity.magnitude? sqrMagnitude? Normalize?
I'm a bit confused on which one is appropriate.
Many thanks
Answer by Kaze_Senshi · Jun 09, 2012 at 10:50 PM
As far I know:
*magnitude = Gives the length from a vector following the formula velMagnitude = sqrt( (x-xo)^2+(y-yo)^2+(z-zo)^2 ), where sqrt is the square root:
*sqrMagnitude is like the formula used in magnitude, but without the squareRoot part. Since squareRoot operation is heavy, this one is good when you just want to compare two vectors and does not need the real length;
*Normalize returns a vector proportional to the original vector, but with length one. This one is good when you want to create a new vector in the same direction of the original but with a fixed length;
So, for me you should use the magnitude one or save the velocities of the 3-axis (x,y,z) it depends what you want to do.
Thanks, that's really helpful!
I decided to take your advice and just add the x, y, z coordinates of the Vector to get the sum of the vector and use that. I thought one of these was the function to get what I needed but I must be wrong. But the explanations are incredibly helpful. Thanks again
Your answer
![](https://koobas.hobune.stream/wayback/20220613072552im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to increase and decrease the animation speed? 1 Answer
Rigidbody magnitude 3 Answers
How to calculate the speed at which a rigidbody2d is actually moving ? 1 Answer
Animation velocity and magnitude 0 Answers
How do I adjust the speed of an animation when preparing a CMU Motion Capture in Blender 2.68? 0 Answers