Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple 2D collision response  RSS feed

 
Jimmy Praet
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!