Rotate player
Hi, kind people of unity forums. I am having trouble with my script as to how I can rotate the player while moving so it would look like the player is actually walking in different directions rather than "strafing" I need my player to rotate so he is always facing the direction he is going to with respect to the button pressed. Much like how it would behave with a joystick. Can anyone help me visualize the code? Here's my rather simple script for player movement (with the help from one of the forum members)
 public float speed = 5; // set speed
 public float distancetoGround;
 void Start()
 {
 distancetoGround = collider.bounds.extents.y;
 }
  
  
 void Update()
 {
  
 if (Input.GetKeyDown(KeyCode.UpArrow))
 {
 Vector3.forward * speed * time.deltatime
 }
  
  
 if (Input.GetKeyDown(KeyCode.DownArrow))
 {
 Vector3.back * speed * time.deltatime
 }
  
  
 if (Input.GetKeyDown(KeyCode.LeftArrow))
 {
 ]Vector3.left * speed * time.deltatime
 }
 if (Input.GetKeyDown(KeyCode.RightArrow))
 {
 Vector3.Right * speed * time.deltatime
 }
  
  
 if (Input.GetKeyDown(KeyCode.Space)) && isGrounded())
 {
 // do jump // assuming you want to check if you can jump
 }
  
  
 }
  
  
  
  
 public bool isGrounded(bool checkGrounded)
 {
 return Physics.Raycast(transform.position,-Vector3.up, distToGround +0.1);}
 }
  
  
Any help will be much appreciated.
this code does not look complete: for example, what is happening on line 14:
 Vector3.forward * speed * time.deltatime
To make your character face the direction you are moving, try something like this in update:
 transform.rotation= Quaternion.LookRoatation(velcocityVector3.normalized);
(not sure how you are storing current velocity, so I just used "velocityVector3")
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                