I’m working on a game where the mob can detect by sight, sound and smell, as of right now I’m having a trouble with sight. The mob is aware of all of it intended targets and will pick one that is the closest to it and will try and see. the problem that I seem to be having is that the ray keep moving downward for some reason and I can figure out why.
void FindTargetBySight()
{
WorldManager WM = GameObject.Find("Main Camera").GetComponent("WorldManager") as WorldManager;
AstarAI ASAI = this.gameObject.GetComponent("AstarAI") as AstarAI;
for (int i = 0; i < WM.Survivors.Count; i++)
{
Distance = Vector3.Distance(this.gameObject.transform.position, WM.Survivors*.transform.position);*
if (Distance <= MinDetectDistance)
{
rayDirection = WM.Survivors*.transform.position - transform.localPosition ;*
RaycastHit DetectedTarget;
if (Physics.Raycast(transform.position, rayDirection, out DetectedTarget,MaxDistance))
{
Debug.DrawRay(transform.position, rayDirection);
if ( DetectedTarget.transform.tag == “Player”)
{
Debug.Log(“i see you”);
}
}
}
* }*
}