- Home /
How do I keep enemies from overlapping
I am making a fps shooter so far I have 4 enemies when ever they chase the player they over lap. This is the code I am using //set the values in the inspector public Transform target; //drag and stop player object in the inspector public float within_range; public float speed; public void Update() { //get the distance between the player and enemy (this object) float dist = Vector3.Distance(target.position, transform.position); //check if it is within the range you set if (dist <= within_range) { //move to target(player) transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed); } //else, if it is not in rage, it will not follow player }
Please Help
Your answer
Follow this Question
Related Questions
This only works for 1 object! 1 Answer
transform.position not working in OnControllerColliderHit 2 Answers
Unity Colliders are Overlapping/Intersecting 2 Answers
Enemys dont collide in follow script 1 Answer
Colliders overlap with follow script 1 Answer