Jump to content
  • Advertisement

Archived

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

tyler_oar

How do I tell the angle?

This topic is 5751 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
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

Share this post


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

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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!