Advertisement

Ping pong virus

Started by January 16, 2003 12:38 PM
1 comment, last by Padu 22 years, 1 month ago
Do you remember that old virus for XTs? Well, it shows some techniques that I need for my game creation. Imagine that you have a point traveling in a 2D plane at a certain speed (doesn''t matter, since speed > 0), and this plane is enclosed by 4 walls. When this point colide with a wall, I want its movement to be reflected just like a pool ball in a pool table. Remembering my high school physics, I know that the angle that the point hit the table should be the reflection angle, but I don''t know how to implement it. I''m controling my point using a coordinate, a traveling speed and a direction in angles, where 90 is going north and 270 is going south. Any help? Pls
Don''t know if I''d be much help, I''m fairly newbish. But the first thing I would try is to determine the angle between the angle of incident and the walls normal, then flip or rotate the point''s direction about that normal.

yckx
Advertisement
For 4-wall simple collisions like that, you can just negate the respective movement speed. Example:

~Object traveling at~
1.56 Xspeed
3.40 Yspeed

~Right Wall collision detected~
-1.56 Xspeed
3.40 Yspeed

Just set it up so going left or up is negative, and right or down is positive. Update the position everyframe by

Xposition = Xposition + Xspeed
Yposition = Yposition + Yspeed

That''s how I would do it for something 2D and simple. But you will have to learn real reflections for more complicated things involving more than 4 boundry walls.

This topic is closed to new replies.

Advertisement