- Home /
 
 
               Question by 
               dev_harsh25 · Oct 06, 2017 at 06:37 PM · 
                collisionnavigationenemyai  
              
 
              Problem with enemy collision with the player(script in description)
Hello! I made a zombie enemy for my zombie style fps. It follows me and looks at me perfectly,but, when the enemy collides with the player , the enemy slides under the player.As a result, the player is standing on the zombie's head.I dont want that . Can anyone help me with the script? Any help will be greatly appreciated <3.
using System.Collections; using UnityEngine; using UnityEngine.AI; public class ZombieAI : MonoBehaviour { public Transform player; public float distance,enemyRange,enemySpeed; NavMeshAgent nav; Animator anim; // Use this for initialization void Start () { nav = GetComponent (); anim = GetComponent (); }
 // Update is called once per frame
 void Update () {
     distance = Vector3.Distance (player.transform.position, transform.position);
     if (distance < enemyRange) {
         transform.LookAt (new Vector3 (player.position.x, transform.position.y, player.position.z));
         transform.localEulerAngles = new Vector3 (0, transform.localEulerAngles.y, 0);
         nav.SetDestination (player.position);
     }
 }
 
               }
               Comment
              
 
               
              Your answer