Forum begins after the advertisement:

[Part 7] Prevent a large group of enemies from overlapping.

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 7] Prevent a large group of enemies from overlapping.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #11691
    Kiefer Neo

    If you are struggling to figure out how you can prevent a large group of enemies from overlapping when they are following the player, here is the solution:

    By adding a small solid collider near their feet / bottom of their sprite may fix the problem. That way, they can still have their body parts overlap, but they cannot occupy the exact same position.

    Norman Harig

    Hey there,

    I am currently struggling with the collision or overlapping behavior of large masses of enemies. In my game they either completely overlap when following the player after a while so that they merge to one enemy (which is not what we want). This happens when I put the rigidbody of the enemies on kinematic or when I do not give them a rigidbody at all.
    Or the enemies do not overlap at all (when I give them a dynamic rb). This, however, is also not good because this waists a lot of space and does not look right.

    In Vampire survivors and other similar games, the enemies can partly overlap but never to a 100 percent. Also the enemies in those games are unable to push the player (but the player can mildly push the enemies), and do not go inside the player sprite but rather stop in front of the player.

    How would you guys efficiently achieve this considering that there are going to be large masses of gameobjects in the game.

    Thank you!


    Hi Norman, I’ve merged your topic into an existing one addressing the same issue. To expand upon this, you use a Dynamic Rigidbody, but shrink the collider of the enemy.

    Then, add another Collider for the enemy marked as a trigger that covers the old area of the collider. This will serve as a hitbox for the enemy, so that the enemy’s damage dealing capabilities are not reduced. However, because it is a trigger, it can accommodate overlap with other enemies’ colliders.

    Does it make sense?

    Norman Harig

    Hey Terenece,
    that makes lots of sense. I tried that in the past but that causes performance issues as soon as there are around 100 enemies in the game.

    I believe this is because the game now has to deal with double the amount of collision due to the second collider on each enemy.


    There are many ways you can work around slow colliders. The easiest way is to reduce the number of Solver Iterations and / or increase the Fixed Timestep in Edit > Project Settings > Physics 2D.

    For the individual objects as well, you can simply the collider shapes (best is to use Circle Colliders as much as possible), turn off Interpolation and use Discrete Collision on the Rigidbody.

    These are just some general tips. Depending on how your project is set up / code is written, there can be many other avenues of opitmisation.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Go to Login Page →

Advertisement below: