How do I make my player model rotate based on the direction he is walking.
Hi! I am new to the forums so take it easy on me! I recently decided to take on a new 2D styled RPG. Currently working on my movement scripts and I am having issues making the player face the direction he is walking.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Movement : MonoBehaviour
 {
     [SerializeField] float moveSpeed = 3f;
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         movement();
     }
     
     
     void movement()
     {
         if(Input.GetKey("w"))
         {
           transform.Translate(0,0,moveSpeed*Time.deltaTime);
         }
         
         if(Input.GetKey("s"))
         {
           transform.Translate(0,0,-moveSpeed*Time.deltaTime);
         }
         moveLeft();
         moveRight();
     }
     
     void moveLeft()
     {
         if(Input.GetKey("a"))
         {
           transform.Translate(0,0,moveSpeed*Time.deltaTime);
         }
         
          if(Input.GetKeyDown("a"))
         {
            transform.Rotate(0,90,0);
         }
 
     }
 
     void moveRight()
     {
          if(Input.GetKey("d"))
         {
           transform.Translate(0,0,moveSpeed*Time.deltaTime);
         }
         
          if(Input.GetKeyDown("d"))
         {
            transform.Rotate(0,90,0);
         }
         //transform.Rotate(0,0,0);
     }
     
 }
 
 
               The biggest issue is if I for example press D. The player looks to the right but if I press D again he turns 90 degrees once more which makes him face the wrong direction. Hope this all makes sense. Again I am new to the forums and new to Game Development so bare with me!
I do see how this code is saying everytime you press A then the player will turn 90 degrees but how could I set it to where if the player is facing left but you press d to turn right he does a 180. With this be multiple if statements?
Your answer
 
             Follow this Question
Related Questions
Making a sword follow mouse movement 1 Answer
Joystick Movement Not Smooth Enough 0 Answers
1st Person shooter, move player forward where cam is facing 1 Answer
My Character dosen´t move 0 Answers
Interesting Script Problem 1 Answer