- Home /
walk crossfade run animation based on joystick position need help please
hi i working on my sidescroll game but i stuck on this problem, walk animation works fine but when my joystick position is bigger or smaller than 0.3 still playing walk animation
here is my script
var JoystickScript:Joystick;
var JoystickPos:Vector2;
var run:AnimationState;
function Start()
{
run = animation["run"];
run.layer = 1;
run.blendMode = AnimationBlendMode.Blend
}
function Update () {
JoystickPos = JoystickScript.position;
if (JoystickPos.x > 0.1){
animation.CrossFade ("walk");
} else if (JoystickPos.x < -0.1){
animation.CrossFade("walk");
} else if (JoystickPos.x > 0.3){
animation.CrossFade("run");
} else if (JoystickPos.x < -0.3){
animation.CrossFade("run");
} else {
animation.CrossFade("idle");
}
}
Answer by aldonaletto · Jun 01, 2012 at 11:50 AM
This is a logic error: if JoystickPos.x > 0.1, the run condition is never tested - thus only idle and walk states are reachable.
Change the **if**s to this:
var jPosX = Mathf.Abs(JoystickPos.x); if (jPosX < 0.1){ animation.CrossFade("idle"); } else if (jPos < 0.3){ animation.CrossFade("run"); } else { animation.CrossFade("walk"); }
it works! thx very much i spend 2 days with it and you solve it in 5 sec... nice job
There's a good reason: I've made this kind of mistake several times too...
Im trying to used this touch script, I need to download something else? This error appears. The name 'Joystick' does not denote a valid type ('not found').
Your answer
Follow this Question
Related Questions
animation walk loops with a stop at the end 0 Answers
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
Animations are different when in lower layers 1 Answer
Speed of animation transitoins 2 Answers