I have vertically moving elevators (3 solid tiles wide) and static solid tiles. Each are separate entities and therefore have their own respective collision routines (to check for, and resolve, collisions with the main character)

I check my vertical collisions after characters vertical movements and then horizontal collisions after horizontal movements.

The problem is that I want my platform to kill the player if it squashes him from the top, and also if he's on a moving platform (that is moving up) that squashes him into a solid block.

Correct behaviour, player on solid blocks being squashed from above by decending elevator

Here is what happens. Gravity pushes character into solid block, solid block collision routine corrects characters position and sits him on the solid block which pushes him into the moving elevator, elevator routine then checks for collision and kills player.

This assumes I am checking solid blocks first, then elevator collisions.

However, if it's the other way around, this happens....

Incorrect behaviour, player on accending elevator gets pushed into solid blocks above

Player is on an elevator moving up, gravity pushes him into the elevator, solid block CD routine detects no collision, no action taken. Elevator CD routine detects character has been pushed into elevator by gravity, corrects this by moving character up and sitting him on the elevator and pushes him into the solid blocks above, however the solid block vertical routine has now already run for this tic, so the game continues and the next solid block collision that is encountered is the horizontal routine. This detects a collision and moves the character out of the collision to the left or right of the block which looks odd to say the least (character should get killed here).

The only way I've managed to get this working correctly is by running the solid block CD, then the elevator CD, then the solid block CD again straight after. This is clearly wasteful but I can't figure out how else to do this.

Any help would be appreciated.

  • \$\begingroup\$ Maybe after resolving a collision, recheck to see if the player is still colliding and if so squish him? \$\endgroup\$ Sep 4, 2013 at 15:44
  • \$\begingroup\$ Hey @UnderscoreZero, thanks for the comment. That's pretty much what I'm doing at the moment (checking Solid block collision, then elevator collision, then solid block again) but it just seems inefficient as I have to run my solid block collision twice in one game-tic. \$\endgroup\$ Sep 4, 2013 at 15:49

1 Answer 1


There are a couple of ways to go about this.

Method 1: The method that I've seen floating around sort of looks like your solution, but would only happen if you do collide with the walls... Something like:

if collide(walls, player)
    if overlap(platforms, player)
if collide(platforms, player) separate()

Method 2: Most of my game Objects have a bitwise flag for 'touching' which tracks which of their sides are being touched at any given moment. I don't know if you have something similar, or can set it up. What I would do is first do the regular wall collision and adjust your player to not pass through the floor. Then, when you check collision with platforms, if your player.touching == FLOOR, then squish them.

  • \$\begingroup\$ Hey @SeiferTim, thanks. I use a boolean flag for 'onElevator' and 'onSolidBlock'. However, the flag for 'onElevator' will only be set once the elevator CD routine has detected and resolved the collision with the elevator, sitting the character on it and setting the 'onElevator' flag to true. At this point, the solid block collision has already been run. Therefore, I still have to run it a second time after for it to say 'yes, player is on elevator and solid block collision detected'. Maybe I've misunderstood? have a look at my example above, could you show me a more detailed solution? Thanks \$\endgroup\$ Sep 5, 2013 at 20:54
  • \$\begingroup\$ I was saying: during the Elevator check, if onSolidBlock when it collides, instead of separating, kill the player. \$\endgroup\$
    – SeiferTim
    Sep 5, 2013 at 21:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .