Public Group

Archived

This topic is now archived and is closed to further replies.

Anyone run into this type of collision detection problem?

This topic is 5194 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I recently completed a Breakout clone. The collision detection works well enough, but it is not perfect. Here is my dilemma: The problem is that the ball moves so fast that it may have totally overrun an object between rendering. For (an extreme) example, say you have a paddle that is 16 pixels high, but your ball travels in 20 pixel increments. If your ball is moving down toward the paddle, the ball could be 2 pixels above the paddle in one frame, and 2 pixels below it on the other. With traditional "is the point in the bounding rectangle" collision detection, this won''t register. Luckily, I took this into account in my program and this can''t happen with the paddle. But it is possible for the ball to occasionally pass through the corner of a block. There are obviously brute force methods of solving this dilemma. The problem is that instead of determining if a point is in a rectangle, we are determining whether or not two lines intersect (the lines being the ball''s displacement vector and the solid edge of a shape). This is expensive (and of course, we also have to determing which side of the block the ball collided with, which is a topic left for another post). So I am wondering what people think a good way of dealing with this is. Should the ball be moved in increments? For example, if it is supposed to move at 20 pixels during each frame, you would move it 5, check for a "point in rectangle" collision, and repeat 3 more times, then go and finish rendering the frame.

Share on other sites
One workaround to this problem :

Lock your FPS to some fixed rate if it goes too low, so once the game goes lower than the FPS limit, it will stick with the desired FPS limit. This way you could predict the maximum displacement of the ball, therefore to arrange the blocks in a cell with edges equal to the maximum displacement.

Share on other sites

How can u minimize ur fps? I mean if it goes down to a certain number wouldnt that mean ur comp simply cant crank out more frames per second? How can u then keep it higher then ur comp can handle?

im not good at c++ but i'll try to give a sollution (this is the beginners forum right?? :D )

maybe u can make a little loop inside ur game loop which updates the position of the ball 1 or more times (depending on how much time has spend since the last frame)

maybe something like this:

while (Time=TimeLastFrame; Time < TimeNow; Time += someNumber)
{
{
do collision detection
}
else
{
updatePosition(TimeNow-Time)
do collision detecting
}
}

Edited by - DaJoostMan on January 30, 2002 6:28:43 AM

Share on other sites
well first off, if you render the graphics in tune with your FPS that''s the usual. However many games have the objects movement be based on time and not frame rate. this way when you do a collision detection the collision is based on where the ball is at a given time and not a given render period which might differ due to system constraints.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 31
• 12
• 12
• 11
• Forum Statistics

• Total Topics
631409
• Total Posts
2999927
×