Question by
Rook1e0ne · Oct 11, 2018 at 12:33 PM ·
raycastraycasting
Raycast Problem That Makes No Sense . Help Needed !!
Basicly i have an enemy and a player and i want to check if the player is within the field of view of the enemy . so i do :
_rayTOdetermineIfPlayerInSight.origin = this.transform.position;
_rayTOdetermineIfPlayerInSight.direction = player.transform.position - this.transform.position;
RaycastHit _hitInfoAboutPlayerInSight;
if (Physics.Raycast(_rayTOdetermineIfPlayerInSight, out _hitInfoAboutPlayerInSight, 100)) // with this Raycast i determine if the player is inSight of the NPC
{
Debug.DrawRay(_rayTOdetermineIfPlayerInSight.origin, _rayTOdetermineIfPlayerInSight.direction, Color.red);
Debug.DrawRay(this.transform.position, transform.forward, Color.blue);
Vector3 _directionBP = (_hitInfoAboutPlayerInSight.point - transform.position).normalized;
angleBP = Vector3.Angle(_directionBP, this.transform.forward); // the field of view of the NPC
if (angleBP <= nPCsFOV && angleBP >= -nPCsFOV)
{
playerInSight = true;
}
}
}
I also have made the anglePB a bublic variable so i can see it in the inspector and with the debug.Draw the raycast is drawn into the scene view. The problem is that when the angle is Between (+25 , +180) from the forward->Left direction of the Enemy the raycast stops. (for the Forward-> Right direction everything is fine).
So my question is "why does the Raycast stop for those angles?".
Thanks Ahead.
Comment
Your answer