How do I tell the angle?

Started by
5 comments, last by tyler_oar 21 years, 6 months ago
Hi all! I am trying to work on my first game. I am using the allegro game programming library and have the graphics and everything and bouncing back and forth for the ball. I have on big question. How do I tell what angle the ball should bounce back at? I will know it''s coordinates and it''s previous coordinates. Given that, how would I tell what angle it is travelling at? Sincerely Tyler Oar
Advertisement
angle of incidence = angle of departure. if your walls are axis-aligned, this turns into a simple 4-parameter test and vector reflection. otherwise, you''ll have to figure out how to reflect your vector around an arbitrary vector, which is the normal of the wall

[twitter]warrenm[/twitter]

Hi, yes i understand that the angle of incidence equals the angle of departure, but how do i figure out what the angle of incidence is?
2D dot product

[twitter]warrenm[/twitter]

OK, let's see.

You have something bouncing off a plat plane..

          |        |        |        |      \y|       \|       /|      /y|=b     /x |    S ____     =a  


S is the coordinate you have.

Let a be the horizontal distance from the original position to the "wall", and let b be the vertical distance (found using the coordinates).

x and y are the two non-right angles.

tan(x) = b / a

then


finally,


It's basic trig.
Hope this helps.

[edited by - gamechampionx on October 19, 2002 7:48:10 PM]
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
As long as it hit things that are aligned either horizontal or vertical you don''t have to calculate the angle. Simply revers the speed.
E.g, if the ball hits the upper wall, then you set speedY = -speedY; The ball will keep the same x speed and will thise bounce away with the same angle as it hit the wall.
ya its really nice if you have a vector class to determine the movement of the object.

then its simply vector physics to do momentums and boucning and the such

This topic is closed to new replies.

Advertisement