reflection/bounce formula help

BlitzMax Forums/BlitzMax Programming/reflection/bounce formula help

Andres(Posted 2009) [#1]
i'm having problems with a formula for my early stage game.

i want to calculate how the object bounces (the angle) from the wall.


i know the angle of the wall, object's moving angle, the point where object and wall collide. If possible then the function or formula would work if the object comes from the other side of the wall too.


Thanks in forward :)


xlsior(Posted 2009) [#2]
Exit angle = 180 - entry angle


siread(Posted 2009) [#3]
Calculate the difference between the object angle and the wall angle.

Then the new object angle is simply, wallangle + difference.


Andres(Posted 2009) [#4]
I have this at the moment, but it doesn't work very well, at somepoint it even does work correctly but then again... not.

					wallAngle = ATan2(wll.getY1() - wll.getY2(), wll.getX1() - wll.getX2()) ' WALL  ANGLE
					objectAngle = ATan2(oy - obj.getY(), ox - obj.getX()) ' OBJECT ANGLE
					
					objectStepLength = Sqr((ox - obj.getX())^2 + (oy - obj.getY())^2)
					objectIntersectStepLength = Sqr((ox - intersect.getX())^2 + (oy - intersect.getY())^2)
					
					obj.setX(intersect.getX() + Cos(360 - (objectAngle - wallAngle)) * (objectStepLength - objectIntersectStepLength) )
					obj.setY(intersect.getY() + Sin(360 - (objectAngle - wallAngle)) * (objectStepLength - objectIntersectStepLength))
					
					obj.setXSpeed(Cos(360 - (objectAngle - wallAngle)) * objectStepLength)
					obj.setYSpeed(Sin(360 - (objectAngle - wallAngle)) * objectStepLength)


basically it's: 360 - (object_moving_angle - wall_angle)


Warpy(Posted 2009) [#5]
Hah, I made a note to write a tutorial on this this morning and then I've been out all day and completely forgotten! Watch this space...


Warpy(Posted 2009) [#6]
Here you go.


Andres(Posted 2009) [#7]
thanks, it seems pretty simple and usefull