#### Archived

This topic is now archived and is closed to further replies.

# How do I tell the angle?

This topic is 5600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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

##### Share on other sites
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

##### Share on other sites
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]

##### Share on other sites
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.

##### Share on other sites
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