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)
Now what I tried is a layout is like roughly 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.
How can I fix this?
footCollider.Cast()
instead ofrigidbody.Cast()
? \$\endgroup\$Cast
method. (But out of curiosity: Is it possible to solve it at the level of the Rigidbody? The use case would be: The intended collision shape is a composite of several colliders, the intended hitbox is a composite of other colliders. Of course I could then do aforeach
and cast all the hitbox colliders but it'd be great for my understanding if there's a top-level solution). \$\endgroup\$Collider2D.Cast
for now, and see if any other suggestions arise. \$\endgroup\$