Hello i am new to unity can someone help me how to do this?
What I would like to do is to make the player rotate left when A is pressed and right when D is pressed. In the past when I try this, it also alters the W and D key(which I have just fixed.

This is my current code for the player:
public class Move2D : MonoBehaviour
{
public float moveSpeed = 5f;
public bool isGrounded = false;
// Start is called before the first frame update
void Start()
{

``````}

// Update is called once per frame
void Update()
{
Jump();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
transform.position += movement * Time.deltaTime * moveSpeed;

}

void Jump()
{
if(Input.GetButtonDown("Jump")  && isGrounded == true){
}
}
``````

}

///easiest way to get the ball rolling…
if (movement.squareMagnitude >0f)
transform.forward = movement.Normalized;

if your game is on a flat surface (always horizontal) you can copy movement vector into a temporary one first, and zero out the Y component before running the code above… to keep your object horizontal.

That will turn character instantly to face the move direction… (eg, whever input direction changes)
you could use rotateTowards… to do things a little smoother…

or here is a vector way to rotate towards target…
transform.forward += (movement.Normalized - transform.forward) * k_accel; //k_accel is turn constant. start from .2f. and tweak it more or less, for faster or slower acceleration

A simple way I found to do that is to do this:

``````SpriteRenderer playerSpr;

void Start{
playerSpr = GetComponent<SpriteRenderer>();
}

void Update{
if(Input.GetKeyDown(KeyCode.a))
{
playerSpr.flipX = true;
}
if(Input.GetKeyDown(KeyCode.d))
{
playerSpr.flipX = false;
}
}
``````