- Home /
How can i play an animation only when i am walking
I was wondering how to play an animation only when i am moving. I have this script to get the animations from the legs:
function BeginAnimation ()
{
var animationComp : Animation[] = GetComponentsInChildren(Animation);
for (var animComp : Animation in animationComp)
{
animComp.Play("left leg animation");
animComp.Play("right leg animation");
}
}
I was wodering how to script that
Answer by superventure · Jan 22, 2011 at 05:36 AM
Hmmm.......
well you can try
}if(animation["walk"].enabled == true){
//do something;
or you can use
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1){
//do something;
Answer by Mike Ledwards · Feb 11, 2011 at 03:39 PM
1st of all its not a good idea to do a seperate animation for left and right leg it will be a ballache to make smooth and blend with your run or jump or whatever.
you must go into your player controller and check if you are grounded and if you are moving... then turn a boolean on if you are..
so if (walking) {
animation.Play(Walk);
}
else {
animation.Play(Idle);
}
an easier way would be to say if(Input.GetKeyDown("w)"){
Walk();
}
you would have to repeat for a,s,d
: any walk sounds will work in the same function
my character doesn't jump and things like that he is just spheres and capsules because i made the character and i am just too lazy to model a character, and if i do an Input.Get$$anonymous$$eyDown(w) and asd, will that work for the arrow keys too?
no i think you would have to use Input.GetButton(leftArrow) and input the arrow keys in the project settings. but don't forget to use if (grounded){
Your answer
Follow this Question
Related Questions
scripts for main menus 1 Answer
Random gen script giving same numbers 3 times in a row 3 Answers
Could some wise person please help with this animation problem 1 Answer
Load XML File ? 1 Answer
How to use callback function of Android? 0 Answers