- Home /
2D Sprite/object rotation changing despite telling it not to
I am trying to prevent the sprite/object from changing it's rotation when the player stopped moving. 
 What is happening right now: whenever I stop moving, the sprite/object looks at the mouse, see below: 
What I want to happen: as soon as I stop moving it should be looking whichever way it was looking last. 
 The script: 
 void FixedUpdate() 
 {
     player_x = Input.GetAxis("Horizontal");
     player_y = Input.GetAxis("Vertical");
     playerRigidBody.velocity = new Vector2(player_x * playerSpeed, player_y * playerSpeed);
 
     if (playerRigidBody.velocity != Vector2.zero) 
     {
         transform.rotation = Quaternion.LookRotation(Vector3.forward, playerRigidBody.velocity);
         moving = true;
     }
     else if(moving == false)
     {
         Vector3 mousePosition = Input.mousePosition;
         mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
 
         Vector2 direction = new Vector2(mousePosition.x - transform.position.x, mousePosition.y - transform.position.y);
         transform.up = direction;
     }
     else 
     { 
         moving = false;
     }
     Debug.Log(moving);
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                