# Collision Detection Failing at faster Speed?

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...

sf::FloatRect.contains(pacman.getPostion);

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!

if ( _rectSwitch.getGlobalBounds().contains( PacMan.getPosition().x, PacMan.getPosition().y )

• 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. Jul 21, 2012 at 3:35
• if i knew how to stop this I wouldn't be asking Jul 21, 2012 at 4:06
• 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. Jul 21, 2012 at 4:07
• 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. Jul 21, 2012 at 4:13

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.

• 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! Jul 21, 2012 at 8:07