So I am Somewhat new to coding (Started last year) so I might get a few things wrong or confused, I apologize preemptively.
I am trying to rotate my player in the same way the game series "Etrian Odyssey" does it, by slowly rotating it towards the desired cardinal direction. I have most of it working now, the player rotates left or right as desired, however, whenever it is looking "south", it is only able to rotate back to where it rotated from (I.E. if the player rotated from the left, it will only be able to rotate right until it goes back at least 1 time).
The following is all the code related to the rotation of the player (excluding the cardinal directions check because it's just brute forcing and enumerations that I don't feel like fixing for now)
This code handles the times where rotation happens and the rotation I want to reach
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
desiredRot = transform.rotation * Quaternion.Euler(0,-90,0);
StartCoroutine("RotateLeft");
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
desiredRot = transform.rotation * Quaternion.Euler(0, 90, 0);
StartCoroutine("RotateRight");
}
This code handles the actual rotation, note that transform.rotate is desired for the effect of the player actually looking around, but it's not imperative, and I would rather it work than it look fancy
case Direction.left:
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
break;
case Direction.right:
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
break;
This code handles when the rotation stops and when the player is able to move after selecting an input
IEnumerator RotateLeft()
{
isMoving = true;
currentDirection = Direction.left;
while (transform.rotation.y >= desiredRot.y)
{
yield return null;
}
currentDirection = Direction.stationary;
isMoving = false;
}
IEnumerator RotateRight()
{
isMoving = true;
currentDirection = Direction.right;
while (transform.rotation.y <= desiredRot.y)
{
yield return null;
}
currentDirection = Direction.stationary;
isMoving = false;
}
Another issue is that no matter what I have tried, the desired rotation isn't perfect, as in, it's never a perfect 90 degree angle, which messes with the movement but honestly, I can worry about that later since movement is my priority, but thought it was worth mentioning in case that was the problem to begin with
I don't particularly remember what I have tried since I've been at this for at least a week, and honestly I'm just very tired at the moment and getting past my social anxiety just to ask this question lol