- Home /
Duplicate Question
http://answers.unity3d.com/questions/586598/how-to-fix-animation.html
Why won't it run
So the problem is when I press D and S it moves across the horizontal line which is what I wanted, but I assigned a parameter to the character so when I am going over a speed of 0.1 the walking cycle starts and when I go over 3, the running cycle starts. How do I make this happen. Here's my code.
var runSpeed : float = 10;
var moveSpeed : float = 3;
var walkingSpeed : float = 0.1;
var golemAnimator : Animator;
function Update ()
{
var input = Input.GetAxis("Horizontal");
if(input < walkingSpeed || input > walkingSpeed)
{
runSpeed = input*moveSpeed*Time.deltaTime;
transform.position.x += runSpeed;
golemAnimator.SetFloat("Running Speed", runSpeed);
}
}
Answer by tanoshimi · Nov 30, 2013 at 10:12 AM
This line is wrong - it's getting executed whatever (well, unless input is exactly equal to walkingSpeed, which, given they're both floats is an unreliable test) :
if(input < walkingSpeed || input > walkingSpeed)
It's a bit hard to see the logic of what you're trying to achieve without seeing your animator (how does "Running Speed" affect your state transitions/blend tree?), but you might find this video useful: https://www.youtube.com/watch?v=Xx21y9eJq1U
I guess he meant
if (input > walkingSpeed || input < -walkingSpeed)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I'm confused with the animator 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Animation spins wildly after completed 0 Answers