Archived

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

How do I tell the angle?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites