I am new to programming so thought I would make a Pac-Man clone to teach myself. I am doing it in C++ using SFML. Anyway, I use a bunch of collision tests. Everything works great.. but if I am going to fast then the collisions simply fail and nothing happens.

Pac-Man is moving though a factor = velocity * frametime;

I am using SFML rectangles to do the tests... eg...


This tests a point in space to see if it is inside the rectangle. The point being the centre of pac-man.

So yeah.. I would love to hear any ideas on this!

Thanks in advance --Jynks

if ( _rectSwitch.getGlobalBounds().contains( PacMan.getPosition().x, PacMan.getPosition().y )
  • \$\begingroup\$ Have you identified the issue? If not, you should do that first, before someone just hands you the solution, as it's a corner stone of game development to deal with stuff like this. \$\endgroup\$
    – William
    Commented Jul 21, 2012 at 3:35
  • \$\begingroup\$ if i knew how to stop this I wouldn't be asking \$\endgroup\$
    – aJynks
    Commented Jul 21, 2012 at 4:06
  • \$\begingroup\$ I'm not telling you to stop it, I'm telling you to find out why it happens. Do some debugging. Debugging is your best friend. Try and do a step by step or frame by frame of the movement, and see what happens exactly. \$\endgroup\$
    – William
    Commented Jul 21, 2012 at 4:07
  • \$\begingroup\$ I don't know SFML, but there are various ways to do a step by step. If you're lucky SFML supports a function that'll run one frame, which is easiest. Alternatively, you can add a breakpoint after the game logic, so it'll freeze each frame, or if you don't want breakpoints, a blocking message box will do. \$\endgroup\$
    – William
    Commented Jul 21, 2012 at 4:13

1 Answer 1


This is a problem inherent with basic AABB (axis-aligned bounding boxes) collision testing. The point is moving so fast that between frames it completely skips the box and "teleports" to the other side.

To solve this, the usual approach is testing a swept path against the box. In Pac-Man this would be either a perfectly vertical or horizontal line.

This explanation is already pretty detailed.

  • \$\begingroup\$ yeah I have changed the code to to check the "next" position of the collision .. by checking the point + the factor that moves it.. then moving the objects so they are touching and stooping and checking.. but I still get teh error ... So I think your have it.. my next movie will be to test of pacman has gone through it and is all the way on the wrong side fo the collidor.. if so move it back.. I'll read that link now.. and thanks! \$\endgroup\$
    – aJynks
    Commented Jul 21, 2012 at 8:07

You must log in to answer this question.

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