I wrote this code about 2 weeks ago and it was working fine in my development scene, however i try importing it into an official level and now the angle is returning a strange number.
//Returns the Angle in Degrees
Debug.Log(Vector3.Angle(transform.position + new Vector3(0, .5f, 0), Enemy.transform.position - transform.position));
//Draws a Ray from the Enemys position in its forward direction
Debug.DrawRay(transform.position + new Vector3(0, .5f, 0), transform.TransformDirection(Vector3.forward));
//Draws a Ray from the Enemy position to the Players position
Debug.DrawRay(transform.position + new Vector3(0, .5f, 0), Enemy.transform.position - transform.position);
//The Angle in use
if (Vector3.Angle(transform.position + new Vector3(0, .5f, 0), Enemy.transform.position - transform.position) < 90f)
{
EnemyNavigation.SetDestination(Enemy.transform.position);
}
All the varibles are assigned correctly and the navmesh is working as well, its just the angle is returning higher than 90 when it shouldn’t as seen here.