float inputX = Input.GetAxis(“Horizontal”);
float inputY = Input.GetAxis(“Vertical”);
if(inputX > 0 && inputY < 0)//D and S
{
rotatationY += inputXturnSpeed;
rotatationY = Mathf.Clamp (rotatationY, 0, 135);
}
else if(inputX < 0 && inputY < 0)//A and S
{
rotatationY += inputXturnSpeed;
rotatationY = Mathf.Clamp (rotatationY, 225, 360);
}
else if(inputX > 0 && inputY > 0)//D and W
{
rotatationY += inputYturnSpeed;
rotatationY = Mathf.Clamp (rotatationY, 0, 45);
}
else if(inputX < 0 && inputY > 0)//A and W
{
rotatationY -= inputYturnSpeed;
rotatationY = Mathf.Clamp (rotatationY, -45, 0);
}
else if(inputX > 0 || inputX < 0)//A or D
{
rotatationY += inputXturnSpeed;
rotatationY = Mathf.Clamp (rotatationY, -90, 90);
}
else if(inputY > 0 || inputY < 0)//W or S
{
rotatationY -= inputYturnSpeed;
rotatationY = Mathf.Clamp (rotatationY, 0, 180);
}
dir.y = rotatationY;
transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(dir.x,dir.y,dir.z), Time.deltaTime * speed);
This code here makes the player rotate and face its direction.
Is there another way to make this code lesser and better? or is this fine which I highly doubt it.