Search code examples
unity-game-enginecollision-detection

Many colliders on animated object makes significant performance impact


I have a problem with colliders on enemies. Of course, colliders are used as hitboxes/hurtboxes you can name it how you want. Each body part like a hand, arm, forearm, foot, etc has a Capsule Collider. We found that we can't really have more than 30 enemies on mobile devices because when the enemy is animated (root motion animations like walking, running etc) we have a heavy load of physics. We tested that, enemies without animations are good, only with animation but without scripts, etc.

Can somebody tell me what we are doing wrong? How do you guys handle stuff like hitboxes on enemies in Unity?

EDIT: This is 3D game, we have one Rigidbody for each enemy


Solution

  • Most games have quite simple hitboxes for Physics collision (like a cylinder/capsule) and more complex hitboxes used solely for raycasting/combat mechanics, separated from the rigidbody (and ignored by physics).

    This means that the physics engine is never doing too much work, and the raycasting/combat hitboxes are only tested when they need to be.

    Mesh Collider options

    Mesh Collider docs explains:

    Is Trigger: Enable this checkbox to make Unity use this Collider for triggering events, and the physics engine ignore it.