Im trying to make it so if a block pushes the player into the wall it triggers my PlayerDie() method. could anyone provide any tips on how to do this in a 2d platformer? The sonic the hedgehog games are a perfect example of what im trying to do.
Two easy ways. The first is to make a trigger area in the “crush zones” that’s disabled most of the time, but is enabled when the crushing object above gets to a certain point. In other words, the big cylinder being at the 80% point in its downward animation switches the trigger on for a second, then it turns off until that happens again. The trigger kills the player if activated, period.
The second way is to make the crushing object have a rail-thin attached trigger area just along its bottom edge, which moves with it, and have a specific collision with that layer on the player object kill the player, but only if the player is isGrounded (not in the air) when the collision occurs.
IMHO, many solution that involves a truly dynamic way of telling when the player is crushed is going to cause bugs in certain scenarios. “Faking it” is likely the best approach. Using a collision contact point test (“if contact is on top side of collider”) in combination with isGrounded might work, for instance, but it wouldn’t be trivial to deal with false positives. Having a test that checks the degree of “penetration” into the collider in OnCollisionStay is another approach, but can be complicated to test for with non-rectangular volumes.
Using distinct layers in the solution is an “absolute” kind of difference that makes it difficult for things to go wrong, thus setting up trigger areas instead of relying on collisions.
Or use a vertical raycast, if the up sensor and the bottom sensor difference are a certain distance = crushed
the combination of movement of the platform/object and the player movement (jumping up against the object) would be hell to work out.
I think of an overlap box, thinner than the object coming down, and a bit smaller than the player.
When this collides with both the object and the player you have a crush.
Or work with 2 invisible smaller sprites with boxcolliders and set 2 booleans for each collission, then check if both are true.
ie: invis box collides with object and invis box2 collides with player.

