Hi all, I am a bit stuck here, as per the title, when the joysticks are idle, how can I leave the player facing in the last moved direction? Currently, he snaps back to default. Here is the code I am using to rotate the player
var angle = Mathf.Atan2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, angle, 0);
I tried this, but it didnt work:
var lastInput = transform.rotation = Quaternion.Euler(0, angle, 0);
if(inputZ == 0 || inputX == 0)
{
transform.rotation = lastInput;
}
Any ideas please?
you are updating the rotation every frame so ofcourse it returns to default. basically only rotate your player when input is detected, then dont do anything
if(input.GetButton("InputName") || input.GetButton("InputName"))
{
//Input can be changed in edit/project setting/ input ( i think )
// there there should be the Horizontal and Vertical premade inputs already, use the main naim of the buttons.
var angle = Mathf.Atan2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, angle, 0);
}