Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

Thanks in advance --Jynks

if ( _rectSwitch.getGlobalBounds().contains( PacMan.getPosition().x, PacMan.getPosition().y )
share|improve this question
    
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. –  William 'MindWorX' Mariager Jul 21 '12 at 3:35
    
if i knew how to stop this I wouldn't be asking –  aJynks Jul 21 '12 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. –  William 'MindWorX' Mariager Jul 21 '12 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. –  William 'MindWorX' Mariager Jul 21 '12 at 4:13
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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! –  aJynks Jul 21 '12 at 8:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.