I have 3 enemies vehicles following my hero but because my hero is moving in a circular path the 3 enemies get progressively together and I need them to keep the distance between them. I tried setting and offset based on the initial position but again as the movement is circular what in the beginning is an x offset becomes a z offset and vice versa.
this is the code for the enemy movement:
public class SmallEnemyMovAI : MonoBehaviour
{
public GameObject heroTarget;
private float speed = 3;
bool finished = false;
Vector3 offset;
void Start()
{
offset = this.transform.position - heroTarget.transform.position;
}
// Update is called once per frame
void Update()
{
if (!finished)
{
this.transform.Translate(Vector3.forward * speed * Time.deltaTime);
Vector3 vec = hero.transform.position - offset;
transform.LookAt(vec);
}
}
}
And this is the hero movement:
public class BigBoatMovAI : MonoBehaviour
{
public GameObject target;
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.RotateAround(target.transform.position, Vector3.up, -0.5f * Time.deltaTime);
}
}