Rotate walking animation

This has been getting to me for a few days now guys, I have read countless pieces of documentation on slerp and things alike but I cannot figure it out. Basically, my character moves right when I press the D key. Everything is fine, the animations are perfect. However, I wish to have my character move right also, I have done this but I want the character to rotate 180 degrees and face the way he is moving. At the moment he is just walking backwards (he is moving in the correct direction). What would be the best way to counter this problem? Thanks in advance!

Please note: When I rotate him, he just adopts the previous controls and moves the opposite way to which he should.

If you need anymore information I will be here for a while :slight_smile:

Script:

var acceleration : float = 100;
var move : float;
var doubleJump : float = 0;
var z : float;
var health : int = 100;
var jumpDelay : boolean;
var shoulder : Transform;
var shoulder1 : Transform;
var hasSword : boolean;
var hasGun : boolean;
var target : Transform;

var rotation : float = 180;

// weapon variables for switch statement.

var weapon : int = 0;

var sword : Transform;
var gun : Transform;


function Update () {


         

// Set the gravity of the level and the starting animation.

     		Physics.gravity = Vector3( 0, -200, 0);
        		animation.CrossFadeQueued("idle");
        	
// If the D key is pressed, set the acceleration to 100 and play the walk animation. If mouse button 0 is pressed and the player has acquired the
// sword, blend the sword animation at the same time.

             if( Input.GetKeyDown(KeyCode.D))
        {
        		acceleration = 100;
    			animation.CrossFade("walk"); 	
    		}

    		if( Input.GetKeyDown(KeyCode.Space) && jumpDelay == false )
   		{
     				Jump();
          				animation.CrossFade("jump");
          					animation.CrossFadeQueued("idle");   
          			jumpTimer();
	          	    		          	
  				}

// If the player is not walking, play the idle animation.

			if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A))
		{
				animation.CrossFade("idle"); 
				
				}

		
// Stop the moonwalking bug. If the player hits both A and D, without this code the accelaration will equal 0 but still play the walking animation, hence 
// the moon walking bug. Additionally, if the player releases one of the keys, the character will move in the right direction.
		
			if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.A))
		{
			acceleration = 0;
				animation.CrossFade("idle");
				
				}
				
		else if (Input.GetKey(KeyCode.A))
		{
			acceleration = 100;
				         move = Input.GetAxis("Horizontal") * acceleration * Time.deltaTime; 
     		transform.Translate (0, 0, move); 
     		  transform.Rotate(0,180,0);
		
				}
				

    	
// Movement script allowing the player to move.
    	
         move = Input.GetAxis("Horizontal") * acceleration * Time.deltaTime; 
     		transform.Translate (0, 0, move); 
}

// The simple jump code with the delay boolean/function.

function Jump(){

       rigidbody.velocity.y = 175;
	}

function jumpTimer(){

		if (animation.IsPlaying("jump"))
			jumpDelay = true;
				yield WaitForSeconds(3);
		jumpDelay = false;
	}

I have removed some of the script so it isn’t tedious to read. There are no errors, some syntax may be missing.

Translate works by default in the space of the object, so when you rotate the object all of your controls are backwards - this is one of the reasons I don’t like using these calls, it’s not obvious what’s going on! Pass Space.World as a fourth parameter to your Translate calls.

Hey guys. We got into this issue , which for me sound really close with what you had. Basically there is a series of animations that have to play based on some input. Idle>Run>… etc So far so good yet there are also the 180 degree and 135 degree turn etc. Here the things become really tangled. We kinda spent several days now trying to find a solution, yet we are stuck with that snap back to original direction which brakes all the flow of movement and of course makes the game unusable. :frowning: @Nercoe : Was your problem similar with this? If so , did you manage to fix it? If yes , can you give me some more detailed hints?
Thank you ! Mihail