Hello. What I want to do is if the left or right button is pressed, I want the player to rotate around itself, and if the forward or backward button is pressed, I want the player to move. With this method below the rotation is working correctly but if I rotate the player 180 degrees, the forward/backward buttons work the exact opposite way. Or when rotated in some other random degree, the forward/backward doesn’t work in the correct direction. Is the problem related to the transform.RotateAround()?
void Movement()
{
if (moveLeft)
{
transform.RotateAround(player.position, Vector3.down, 90 * Time.deltaTime);
}
else if (moveRight)
{
transform.RotateAround(player.position, Vector3.up, 90 * Time.deltaTime);
}
else
{
horizontalMove = 0;
}
if (moveForward)
{
verticalMove = speed;
}
else if (moveBackward)
{
verticalMove = -speed;
}
else
{
verticalMove = 0;
}
}
In the Update(), the Movement() is called, and in the FixedUpdate, velocity is set:
player.velocity = new Vector3(horizontalMove*Time.deltaTime, player.velocity.y, verticalMove*Time.deltaTime);