I'm terribly sorry I'm asking this question YET AGAIN, but I can almost guarantee that this will be the last time I'll have to ask.

I'm currently on the verge of FINALLY getting these collisions to work for my game, made with libGDX in Java. My collisions use the same method as (and are basically copied and modified code from) the XNA Platformer example (here) where the direction of the collision is based on the rectangle where two objects are overlapping.

The collisions themselves almost work perfectly, but for some reason, holding down/up and left and colliding with the floor/ceiling while doing so doesn't seem to work well. I'm not at all sure why.

Instead of vaguely giving my problem and snippets of code, I've decided to instead provide a binary and the source of the game I have so far so you can see for yourself what my problem is. Link. (Note: make sure you unzip everything into a folder somewhere or it will not work)

You'll find the collision code in the method workingCollisions() in Link.java. Please excuse the messy code and terrible graphics as this whole thing is in pre-pre-alpha.

If anyone is kind enough and helps me out here, you are the best person ever. I'm completely desperate; I've been trying this on and off for months and I just can't get it to work. I cannot thank you enough.

  • 4
    \$\begingroup\$ Maybe is not that clever idea to post binaries... A video of what happens that should not may help better. Explaning how the thing is supposed to work and what the implementation differs on where it works and where it dont may be useful firstly to you. \$\endgroup\$
    – FxIII
    Nov 25, 2011 at 8:05

1 Answer 1


I'm not going to go through your code, but one thought is that, if you're "holding down" navigation buttons and moving relatively quickly, your bounding box may skip from one side of the object you're colliding with to the other in a single step.

One way to avoid this is to calculate a ray from the original position to the new one, and check that for intersections with the other objects in your scene. Since you're checking the path the object takes instead of just it's new position, it'll catch anything that should have triggered a collision.


You must log in to answer this question.

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