Hi! I want to make charecter rotate in direction of Movement. help. Thanks in advance

private void Update(){
mx = Input.GetAxisRaw(“Horizontal”);

if (Input.GetButtonDown("Jump") && IsGrounded()) {
	Jump();
}
if (Mathf.Abs(mx) > 0.05f) 
{
	anim.SetBool("IsRunning", true);
} else {
	anim.SetBool("IsRunning", false);
}
if (mx > 0f) 

{
	transform.localScale = new Vector3 (2.18f, 2.35f, 1f);
} else if (mx < 0f)  
{
	transform.localScale = new Vector3(-2.18f, 2.35f, 1f);
}

anim.SetBool("IsGrounded", IsGrounded());

}

I’m pretty sure this is what you are looking for:

If anyone knows the solution of my problem kindly help.

Setting the local x scale to -1 is usually used in 2D games to make the image mirrored and thus the character face the opposite direction.

Assuming that your game is 2D, I don’t know why this wouldn’t work off the top of my head but if you do want to rotate it to mirror it instead you can replace your local scale changes with local rotation changes:

if (mx > 0f) 
{
    transform.localRotation = Quaternion.Euler (0f, 0f, 0f);
}
else if (mx < 0f)  
{
    transform.localRotation = Quaternion.Euler (0f, 180f, 0f);
}

Alternatively, if you need to preserve the rotation around the other axes then use a function like this:

private void SetRotationDirection(bool forwards)
{
    var eulerAngles = transform.localRotation.eulerAngles;
    eulerAngles.y = forwards ? 0f : 180f;
    transform.localRotation= Quaternion.Euler(eulerAngles);
}

As this will mean that the original x and z rotations will be maintained as we only set the y rotation. To use this, call SetRotationDirection(true) in the first part of the if-statement and SetRotationDirection(false) in the second else-if part (instead of the localRotation change). This bool is used to determine whether we use a rotation of 0 or 180, as seen in the second line of the function.