cross-post - answer at gamedev stackexchange
I'd like to do the following:
- Characters (player, enemies) have a collider for collision with the world (= other characters/obstacles/etc)
- Characters have another collider acting as a hurtbox (most likely larger than the collision)
How can I achieve this?
What I tried is a layout roughly like this:
Character root GameObject [layer is "default"]
- Rigidbody2D (kinematic, full kinematic collision)
- BoxCollider2D (rather small, just the feet of the sprite)
- `MovementController` script with collision detection using `rigidbody.Cast` and MovementFilter set to layer "default"
* `Hurtbox` child object [layer is "hurtbox"]
- BoxCollider2D (covers most of the sprite (or more to make some enemies easy to hit))
LayerMatrix: Two user defined layers: Hitbox, Hurtbox. There's no interaction with the predefined layers and the only interactions among these is
Hitbox - Hurtbox [used for damage, etc: when a hitbox collides with a hurtbox, things happen]
Now the problem seems to be that all the Colliders in the child objects attach themselves to the ribidbody in the parent even though they're on different layers. And so the rigidbody.Cast uses the combined shape of both the "collision" box collider AND the "hurtbox" box collider.