- Home /
I'm making a game where 1-4 enemies follow me. I want to make the Enemy AI's move at different speeds, so they won't combine and become one ball. How do I do that? Do I make 4 different scripts, one for each enemy? Thanks in advance
using UnityEngine;
using System.Collections;
public class Enemy_AI : MonoBehaviour
{
Transform tr_Player;
float f_RotSpeed=3.0f,f_MoveSpeed = 3.0f;
// Use this for initialization
void Start ()
{
tr_Player = GameObject.FindGameObjectWithTag ("Player").transform;
}
// Update is called once per frame
void Update ()
{
/* Look at Player*/
transform.rotation = Quaternion.Slerp (transform.rotation , Quaternion.LookRotation (tr_Player.position - transform.position) , f_RotSpeed * Time.deltaTime);
/* Move at Player*/
transform.position += transform.forward * f_MoveSpeed * Time.deltaTime;
}
}
Answer by tanoshimi · Apr 24, 2016 at 07:42 AM
Local avoidance (of static obstacles, or other NPCs) AI is commonly achieved using steering behaviours. Co-ordination of squad behaviours to avoid flocking too closely together or "queuing" to get through a narrow gap sometimes requires a leader that sets orders for the other members of the group.
There's plenty of examples on the net to get you started, try:
Thanks for your help. I chose to make additional scripts (one per enemy AI), adjusting the speed for each enemy and added rigidbodies to them. It's working great.
Your answer
![](https://koobas.hobune.stream/wayback/20220612075451im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to adjust the speed of an object? 1 Answer
How to change pace by pressing different buttons once? 1 Answer
Animation speed 2 Answers
Changing direction without altering velocity 1 Answer
How do I script speed in java? 0 Answers