Keeping Distance

Hi there,
I am trying to figure out how to have a group of enemy class, chase the player, while keeping distance from each other. At the moment they all end up bundling into the same area eventually. I would like to keep each a minimum of a unit apart.

So, all enemy are chasing the same transform, how to I insure that they keep a boundary between themselves while continuing to chase.

I was using OnTriggerStay, and I can get distance, but how to I impose that distance to be kept?

There are many ways, try using a parent.

  • Parent all enemy units to a empty gameObject or whatever you want.

  • Tell the empty game object to follow the player.

If you are using navmeshagent you will have to extend your radius and/or collider so that it covers all the enemies.

the nasty solution: Put colliders on them all that only collide with that collider layer

proper solution 1: Have a ring leader, generate points around ringleader, based on distance + pattern (rotation offset), assign units to a position, have them constantly move to that position

Right.Thanks!
Colliders would probably do.
Cheers!

I knew thats teh solution you would pick :wink:

Yah. Not totally sure why I thought I had to calculate it.

Another solution (not sure how good) would be to use overlap sphere or circle and change velocity to move away from returned colliders

Thanks,
Might get sloppy, and seems something colliders would do internally.

Yup can totally underatand. Correct me if I am wrong but using colliders might unintentionally push the chasers closer to the target which I assume is unwanted.

Not necasrily. My issue is calculating a push away that looks natural. I think collisions can handle this.

Fair enough :slight_smile:

1 Like

It may make your things slide around a bit… but if it looks acceptable, who cares.