- Home /
 
 
               Question by 
               nowherey · Jun 18, 2013 at 09:35 AM · 
                rotate2d animation  
              
 
              2D animation,rotate the character walking animation once.
Hi,everyone! I'm working on a 2D RPG game.The walking animation is based on the skeleton model.Now I had done the walking left animation,and I want to reuse it on the walking right by rotate it. I want to rotate the animation when the rightarrow key pushed,and I want to rotate only once. Here is my code:
         if ( velocity.x < 0  )                                                    // walk left
         {
               velocity *= walkSpeed;                                              // move left based on walk speed
               ruyinAnimation.CrossFade("walk_left"); 
          }
         if ( velocity.x > 0 )                                                     // walk right
         {
               velocity *= walkSpeed;                                              // move right based on walk speed
               transform.Rotate(0,180, 0);
               ruyinAnimation.CrossFade("walk_left");                 
         }
         
         
         
         if( velocity.x == 0 && moveDirection == 1 )  
         {
         ruyinAnimation.CrossFade("stand_left");              
         }
         
         if( velocity.x == 0 && moveDirection == 0 )    
         {          
          ruyinAnimation.CrossFade("stand_left");                           
         }
 
               When I pushed the rightarrow key,the animation rotate again and again... I just want it rotate once... Will somebody please help me?
PS:sorry for my poor English...
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Ben-Stoneman · Jun 18, 2013 at 03:54 PM
In your script you say:
 if ( velocity.x > 0 )
         {
               velocity *= walkSpeed;                                               
               transform.Rotate(0,180, 0);
               ruyinAnimation.CrossFade("walk_left");           
         }
 
               This means, when the walk speed is greater than 0, rotate the character. So it will constantly rotate until walk speed is less than 0.
Your answer