- Home /
Playing sprint animation with vertical axis?
So I have made this JS script that works fine with walking. When the vertical axis is 0.01 or higher it goes from the idle to the walking animation.
The question is, how do I get it to play a sprint animation this way? Any other way is also fine aslong as it's useable in this script.
I use the parameters 'Walking' and 'Sprinting'.
#pragma strict
internal var animator : Animator;
var hor : float;
var ver : float;
function Start () {
animator = GetComponent(Animator);
}
function Update () {
hor = Input.GetAxis("Horizontal");
ver = Input.GetAxis("Vertical");
}
function FixedUpdate() {
animator.SetFloat("Walking", ver);
animator.SetFloat("Sprinting", ver);
}
Thanks!
Answer by Agoras · Jan 28, 2015 at 07:58 PM
The quickest way to get that to work in this script is probably to add a couple if statements where you are setting the floats. Something along the lines of: if(ver > 0.01 && ver <= 0.7) do Walking and if(ver >0.7) do Sprinting
That said I would suggest sending the ver float to the animator once as "speed", and handling the range for speed in the animator controller with transitions or a blend tree.
Well now I have this and it doesnt do anything anymore!
#pragma strict
internal var animator : Animator;
var hor : float;
var ver : float;
function Start () {
animator = GetComponent(Animator);
}
function Update () {
hor = Input.GetAxis("Horizontal");
ver = Input.GetAxis("Vertical");
}
function FixedUpdate() {
if(ver >= 0.01 && ver <= 0.7)
{
animator.SetFloat("Walking", ver);
}
if(ver >= 0.7)
{
animator.SetFloat("Sprinting", ver);
}
}
Nothing, but a tutorial I looked at it did it exactly the way I had the code on first post. Tho I feel like it can't recognize sprinting with vertical axis cause in the end walking and sprinting has the same vertical axis.
Do you have any other way?
Its just you have both
ver <= 0.7
and
ver >= 0.7
You will need to remove the = from one of them. (You've done it in your text but not in your code).
Your answer
Follow this Question
Related Questions
How to call a animation to transition to the next. 0 Answers
How To Play Animation 1 Answer
2D Animation does not start 1 Answer
Animator Trigger Not Working 1 Answer