- Home /
calculating player rotation direction
so, I've been trying to calculate the rotation direction of the player using coroutines and have run into some issues after doing some research... I'm new to using these, and know the issues are with improper setup of the code itself. what i'm hoping is you can see what I've done improperly...
thank you in advance!!
public enum playerTrans { Left, Right, Idle }
private bool continuePlayerRotationCalculation = false;
void Start()
{
StartCoroutine(PlayerRotationCalculator(transform));
}
void DoStartPlayerRotationCalculation()
{
bool ContinuePlayerRotationCalculation = false;
IEnumerator PlayerRotationCalculator(Transform transform.rotation);
{
yield return null;
ContinuePlayerRotationCalculation = true;
float oldYAngle = 0;
float newYAngle = 0;
bool isIdle = false;
oldYAngle = Mathf.Abs(transform.rotation.eulerAngles.y);
while (ContinuePlayerRotationCalculation == true)
{
newYAngle = Mathf.Abs(transform.rotation.eulerAngles.y);
if (oldYAngle < newYAngle)
{
isIdle = false;
oldYAngle = newYAngle;
Debug.Log("Left");
anim.SetBool("isTurningLeft", true);
anim.SetBool("isTurningRight", false);
}
else if (oldYAngle > newYAngle)
{
isIdle = false;
oldYAngle = newYAngle;
Debug.Log("Right");
anim.SetBool("isTurningLeft", false);
anim.SetBool("isTurningRight", true);
}
else if (!isIdle)
{
isIdle = true;
oldYAngle = newYAngle;
Debug.Log("Idle");
}
yield return null;
}
}
}
void DoStopPlayerRotationCalculation()
{
continuePlayerRotationCalculation = false;
}
What in gods name made you decide to perform player rotation in a coroutine?
i'm not perfor$$anonymous$$g rotation in the coroutine itself. the only thing the coroutine is for is to calculate what direction the player is rotating.
i already have rotation in another part of my code. this isn't what makes the player rotate.
but that said, what would you reccomend to find current rotation? is there a simpler way or...?
I guess I'm just confused, wouldn't you know if the player was turning left or right in your controller script? Is it using a nav agent? Because you can still figure out turning direction from a nav agent by calling to the Nav$$anonymous$$eshAgent.angularSpeed field.
Your answer
Follow this Question
Related Questions
How can you tell if a gameobject is looking directly at another gameobject? 1 Answer
WaitForSeconds Not Working 4 Answers
Shooting when raycast hits player with delay between shots, Coroutine not working as I intend 1 Answer
Need Help with a Null Reference 1 Answer
SpeedBoost won't reset : Problem with either WaitForSeconds or Coroutine (Solved) 2 Answers