- Home /
Animation Playing Automatically Even When No Input Is Given
I am using a modified version of the SideScrollControl script that comes with unity. I have made it so animations play moving the joystick left and right. It was working for a while, now all of a sudden the wrong animation starts playing and stays playing even though I have an Idle animation that should play. Here is a snippet from my code:
function Update() { var movement = Vector3.zero; // Apply movement from move joystick if ( moveTouchPad.position.x > .1 ) { movement = Vector3.right * forwardSpeed * moveTouchPad.position.x; animation.Stop("Right"); animation.Play("Left"); } else if ( moveTouchPad.position.x < .1 ) { movement = Vector3.right * backwardSpeed * moveTouchPad.position.x; animation.Stop("Left"); animation.Play("Right"); } else { animation.Stop("Right"); animation.Stop("Left"); animation.Play("Idle"); }
Answer by winner1324 · Feb 17, 2014 at 03:24 PM
I figured it out. In these two lines:
if ( moveTouchPad.position.x > .1 )
else if ( moveTouchPad.position.x < .1 )
The x position is the coordinate of the GUITexture in unity. I had the position to .05, so naturally the animation played automatically.
I fixed it by replacing .1 with .05 and -.05; The .05 being the right movement the -.05 being left movement. Here is the updated code snippet:
`function Update() { var movement = Vector3.zero;
// Apply movement from move joystick
if ( moveTouchPad.position.x > .05 )
{
movement = Vector3.right * forwardSpeed * moveTouchPad.position.x;
animation.Stop("Right");
animation.Play("Left");
}
else if ( moveTouchPad.position.x < -.05 )
{
movement = Vector3.right * backwardSpeed * moveTouchPad.position.x;
animation.Stop("Left");
animation.Play("Right");
}
else
{
animation.Stop("Right");
animation.Stop("Left");
animation.Play("Idle");
}`
Your answer
Follow this Question
Related Questions
Joystick animation on android 0 Answers
Character Animation Assistance 1 Answer
Animation not playing , please help 1 Answer
animation.play plays on all cloned objects 0 Answers
How would I go about carrying out another object's animation IN C#! 1 Answer