- Home /
walk to run animation
how can i make this code that when i press T its switches the animation to run and when i press T again it changes back the animation to walk this is what i got now and if you can help me that will be great if your confused just comment
animation.wrapMode = WrapMode.Loop;
animation["jump"].wrapMode = WrapMode.Clamp; animation["shoot"].wrapMode = WrapMode.Clamp; animation["grab"].wrapMode = WrapMode.Clamp;
animation["idle"].layer = -1; animation["walk"].layer = -1; animation["run"].layer = -1;
animation.Stop();
function Update () { if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) animation.CrossFade("walk"); else animation.CrossFade("idle"); if(Input.GetKeyDown("t")) animation.CrossFade("run");
if (Input.GetButtonDown ("Jump"))
animation.CrossFade("jump");
if (Input.GetButtonDown ("grab"))
animation.CrossFadeQueued("grab", 0.08, QueueMode.PlayNow);
if (Input.GetButtonDown ("Fire1"))
animation.CrossFadeQueued("shoot", 0.3, QueueMode.PlayNow);
}
Answer by AnaRhisT · Jun 20, 2010 at 01:53 PM
if(Input.GetKeyDown("t"){
if(animation.CrossFade == "run"){
animation.CrossFade("walk");
}
else{
animation.CrossFade("run");
}
}
Answer by Tetrad · Jun 20, 2010 at 05:01 PM
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("walk");
else
animation.CrossFade("idle");
You need to change this code. Basically you're crossfading to "idle" every frame that you're not moving and not pressing down on T.
You need to add another variable to set the "idle but running" state when you press T so you're not crossfading to idle every frame.
Your answer
Follow this Question
Related Questions
Locomotion System (By Rune Skovbo Johansen) 1 Answer
why my Animation "Run" wont work 1 Answer
Lerpz ThirdPersonPlayerAnimation bug - running at walking speed 1 Answer
How do i make my player go from walk animation to run animation using blend trees? 2 Answers
Speed of animation transitoins 2 Answers