,Crashing in do while loop when it should be exiting
Code: dino = GameObject.FindGameObjectWithTag("Dino");
float aSide;
float bSide;
float hypotenuse;
aSide = dino.transform.position.y - child.transform.position.y;
bSide = dino.transform.position.x - child.transform.position.x;
hypotenuse = aSide * aSide + bSide * bSide;
hypotenuse = Mathf.Sqrt(hypotenuse);
float privatehyp;
do
{
gameObject.transform.eulerAngles += new Vector3(0, 0, 1);
aSide = dino.transform.position.y - child.transform.position.y;
bSide = dino.transform.position.x - child.transform.position.x;
privatehyp = aSide * aSide + bSide * bSide;
privatehyp = Mathf.Sqrt(privatehyp);
} while (privatehyp < hypotenuse);
It crashes when the rotation matches the "dino" object meaning it crashes when it should be exiting. It rotates faster than the dino moves so eventually the gameobject rotates until the new hypotenuse is no longer smaler than the old, it should just exit, right? It doesn't, it crashes, why? ,Code: dino = GameObject.FindGameObjectWithTag("Dino");
float aSide;
float bSide;
float hypotenuse;
aSide = dino.transform.position.y - child.transform.position.y;
bSide = dino.transform.position.x - child.transform.position.x;
hypotenuse = aSide * aSide + bSide * bSide;
hypotenuse = Mathf.Sqrt(hypotenuse);
float privatehyp;
do
{
gameObject.transform.eulerAngles += new Vector3(0, 0, 1);
aSide = dino.transform.position.y - child.transform.position.y;
bSide = dino.transform.position.x - child.transform.position.x;
privatehyp = aSide * aSide + bSide * bSide;
privatehyp = Mathf.Sqrt(privatehyp);
} while (privatehyp < hypotenuse);
Crashes when the rotation matches the "dino" object, meaning it crashes when it should be exiting. It rotates faster than the dino moves and crashes when it catches up, why?
Comment
What error is it throwing, and which line is it throwing it on>
Your answer
