Best way to detect if player is being squeezed?

corbanwolf

  • Posts: 221
I was thinking about detecting whether both top and bottom or left and right sides of an actor are being collided with tile or actor. Do you have better ideas how to achieve that?

And one problem. When the player got squeezed very much that it goes out of bounds it ends up inside a tile before his lives runs out. How to prevent actor from going out of bounds?
♪♪♪♪♪♪

merrak

  • *
  • Posts: 2596
Have the player hold an orange. If you get orange juice, it's being squeezed.

I've had mixed results with the '(direction) of actor was hit' checks, but that would be the simplest solution. I don't think it's reliable with non-rectangular collision boundaries--at least, that's the scenario I seem to have trouble with.

You can make your own '(direction) of actor was hit' check by detecting if any collision has occurred, then comparing the positions of both actors. I'd use a two-boolean check (the strategy that the on-ground behavior included with the jump and run kit uses) to set a flag for each of the four directions. Collision with ground (if you have gravity in your scene, that is) can also count as collided on bottom.

Collision resolution will eventually push the actor out of bounds. The collision box won't compress automatically, so the only thing left to give is the position of the box itself. You can switch the player to an animation with a squeezed collision box... or even just have a squeezed animation with no collision box at all.

JeffreyDriver

  • *
  • Posts: 2243
I've done it before. It was just checking if the actor was on the ground. If it was, and was hit from above by a platform then it triggered death. I guess if you want to stop the actor being pushed through tiles, stop the actor that's crushing it.