- Home /
Prevent gameobjects from overlapping - 2D
I have a player game object. And a couple of enemy game objects with reference to player's transform position. Whenever the enemies spawn they move toward the player's transform position, overlapping with all the other enemies. How can I prevent my enemy game objects from overlapping each other or at least have an offset from each other? The enemy has a Box collider with trigger enabled, Rigid body type set to Kinematic
Are they boxcollider2Ds and rigidbody2Ds? Also, if the enemy GOs go toward the player pos, then I also assume that youve set up a nav mesh agent for each enemy. If not, there are a lot of settings to play with, such as the areas the enemy can walk on, or the obstacle avoidance radius which prevents agents from walking into each other or just staying very close to walls all the time, and causes them to spread out a little bit.
Yes, I'm using both Box collider 2d & Rigidbody 2D. I'm not using Nav mesh for 2D. Haven't yet gone through Nav $$anonymous$$esh. Can I achieve the result I've mentioned in the question with Nav mesh 2D or is there one for 2D?
With nav meshes, the gameobjects will never collide or go near other objects with colliders, never $$anonymous$$d overlapping, so yes, you should receive the result youre looking for.