You are being forwarded to the lastest updates ot his page!
Or you can Click Here if it doesn't work or you don't wish to wait.

Simple 2D collision response

knot
Hi,

I am having some problems in calculating the collision response of the following situation:

I have a rectangle moving at a certain dx and dy velocity inside an octagon (It's a dice game). When it collides with an edge of the octagon I need to calculate the new dx and dy values.

The top and bottom edge is offcourse: dy=-dy
And left and right edge: dx=-dx

But what about the other edges


ejfried
Hi Jimmy,

As this is basically a geometry question, it's a perfect candidate for our games programming forum. I'm going to move this thread there, where I'm sure it will be answered quickly.


Jim Yingst
For the bottom right and upper left corners:

newDx = dy
newDy = dx

For upper right and bottom left:

newDx = -dy
newDy = -dx

Probably you'll want to implement these as something like

double temp = dy;
dy = dx;
dx = temp;

and

double temp = -dy;
dy = -dx;
dx = temp;

[ October 03, 2004: Message edited by: Jim Yingst ]


Layne Lund
It will take a little bit of trigonometry to make the equations for the other for "diagonal" sides of the octogon. I don't know all the equations you need. However, a simple google search turned up a promising tutorial. I'm sure you can google for more material if this is too far over your head.

HTH

Layne


Jim Yingst
Um, all 8 sides of the octagon are covered already, aren't they? IT's true that a little trig would be needed to handle bouncing off surfaces at other angles, but for surfaces at 0, 45, 90, 135, 180, 225, 270, and 315 degrees, no trig is needed.