- Home /
Speed won't work as a parameter
Hello. I'm trying to make my idle animation transition into walking animation for my character. I have a custom character and I'm controlling it with the 3rd person controller script that comes with unity.
The only real problem that I'm facing is that when I try to set Speed as a float parameter in the animator (as Unity tutorials suggest) and move my character, the float doesn't change, making it useless as a parameter.
I'm rather confused, since I was led to believe that Speed with a capital 'S' accesses some variable somewhere in Unity that keeps track of the speed of your character.
Is there something I need to change, or do I need to write the script that keeps track of the speed myself?
There's no such thing as " Speed with a capital 'S' accesses some variable somewhere in Unity that keeps track of the speed of your character." - that's just a variable, name it whatever you want. There must be something you're doing wrong, did you make sure you got your transition states set up correctly? - Try and debug, is your script changing the variable?
Ah, Ok. It turns out that I was just entirely disillusioned about how the system works; I'm brand new to Unity. I think I'll write a script that updates a variable to measure speed and use that as my parameter.
Checkout the $$anonymous$$ecanim tutorials on youtube, there's many. There's one from Unity official. They also have one for their S$$anonymous$$lth game tutorial series, good series for intermidates. Good luck.
Answer by verenion · Aug 14, 2013 at 09:39 AM
"Speed" is not a special variable of any kind. You could call it "ThisIsMyVaraibleThatSaysHowFastIGo". I think the issue, is that you have't written a script that changes this. Something like this should work:
void Start()
{
// get the animator
animator = GetComponent<Animator>();
}
void Update()
{
// your speed is either +1, 0, -1 depending on if you are going forward
// or backwards. This may change depedning on how you control your character
float inputSpeed = Input.GetAxis("Vertical");
// set the float for the speed value
animator.SetFloat("Speed", inputSpeed);
}
That is a C# script. This then needs to be attached to the gameobject in your scene that has the animator attached.
Will there be any conflict if there are both C# scripts and JS scripts attached to one object?
By the way, I think you meant to write inputSpeed ins$$anonymous$$d of playersCurrentSpeed in the SetFloat method.
Nope, they are compiled anyway, it makes no difference. Sorry, inputSpeed is actually from my game, I was supposed to rename it to playersCurrentSpeed to make it more clear. If this answer helps, upvote it and make it an an answer! If you need any more help, just let me know.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Another way to reference scripts? 2 Answers
Assigning varaibles to prefabs 1 Answer
Declaring Variable in Child & Access as Parent 2 Answers
Change variable value of a script from another script. both in different Game object 1 Answer