Pixel based collision detection

Started by
0 comments, last by heat 22 years, 9 months ago
I''m developing a small pinball game. My problem is determining the angle the ball gets after a collision. I''m using pixel based collision detection because the small size of the game (the board is about 80x150 pixels and the active area of ball is just one pixel). Mainly i''m concerned of the ball''s behaviour when it hits an arc (or curve or something). Sometimes ball gets such an angle that on the next frame it will collide again and even get inside a wall. Anyway what i''m doing now is: 1. calculate angle of the ball''s velocity 2. reflect(?) it around wall''s normal vector 3. calculate new velocity vector from the new angle Any better ideas?
Advertisement
I''ve had a lot of ''fun'' with this aspect myself, and it''s not collision detection that''s the problem. Collision detection is never hard, it''s collision reaction that''s annoying.

A few points to consider. Are you using varied time frames, like measuring how long it''s been since the last update and moving your ball accordingly, or are you moving a specific(small) amount each ''frame''. You can have the problem with both approaches, but it''s more likely with varied speeds, because on one frame, you might enter the wall by 10 units, but the next frame only lets you exit by 5 units and then you''re stuck.

What you need to do though is to never enter the wall. When you calculate your collision, you need to break the movement of the objects down so that as soon as they ''collide'', they react, and you move the ball in it''s new direction at the same time.

I''m not sure if that''s clear, but basically, when a ball is going towards a wall, you might be 2 units away in frame 1, and then move 5 units in the next frame, so what should happen is, you check collision with each unit, and on the second check, you get a collision, and bounce the ball back in its new direction 3 units.

G''luck,
-Alamar

This topic is closed to new replies.

Advertisement