- Home /
 
Enemy raycast chase player
I need help in trying to make an enemy chase the player by using a raycast to see him. The problem is when the player is above the platform the enemy is on. I still want the enemy to be able to see the player

i took the ignoreCollision bit out becoz the player seems to fall thru the platform??
Here my code:
 function FixedUpdate()
 {
     var hit : RaycastHit;
     var dir = transform.TransformDirection(Vector3.right);
     
     if (Physics.Raycast (transform.position, dir, hit, 600) ) 
     {    
         Debug.DrawLine(transform.position, target.position, Color.red);
         if(hit.collider.tag == "Player")
         {
             print("chase");
             Chase_Player.observed = true;    
         }
         //else if(hit.collider.tag=="Platform")
         //{
             //print("platfrom");
             //Physics.IgnoreCollision(hit.collider, target.collider);
         //}
         else
         {
             print("stop");
             Chase_Player.observed = false;    
         }
     }
     else
     {
         Chase_Player.observed = false;    
     }
 }
 
              The common (and perhaps the best) answer is to place the platforms on a different layer than the rest of your game objects and then use the layer$$anonymous$$ask parameter in the Raycast() so the platforms will not be seen.
Your answer
 
             Follow this Question
Related Questions
How can I check the line of sight to see if the player is visible to the enemy? 1 Answer
Getting the player to retreat a certain distance from the player 1 Answer
can foe hear us? 1 Answer
How to stop the enemy from jumping when chasing the player ? 1 Answer
How to make "enemy" have a frustum(cone) view and not a circle radius 2 Answers