Collider2d cast to player child ignores the child
I'm trying to implement robust collision detection for a platformer. Collider2d.Cast() seems like the perfect thing to use for that. However, the platforms are slimmer than the character sprite, and sometimes a side collision cast upwards still sees player sprite, therefore registering a downward collision when it's not one.
I tried applying a rigidbody child "leg hitbox" to the character sprite and setting it to a new layer, then masking that layer, however I must be missing something about how filtering or casting to children works because cast seems to ignore the child.
Here's the relevant snippet. What am I missing?
...
RaycastHit2D[] hits = new RaycastHit2D[10];
ContactFilter2D filter = new ContactFilter2D();
filter.SetLayerMask(LayerMask.NameToLayer("Player Collision"));
filter.useLayerMask = true;
if (collision.collider.Cast(Vector2.up, filter, hits) > 0)
{ ...
Your answer
Follow this Question
Related Questions
2D Cast Problem 0 Answers
2D Sprite concave mask with holes 0 Answers
Could someone explain to me how Collider2D.cast() works?, how to use it? 0 Answers
Inconsistent 2d collider hit registration 3 Answers
CircleCast hit its origin... 0 Answers