Jump to content
  • Advertisement

Archived

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

evilclown

Vectors bouncing

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

How would I bounce a vector off a wall or paddle? To get the new vector from a paddle collision would I add the vectors and do something else? I have no idea how to do the wall collision, but I know the angle between the ball and wall is the same as the new ball direction and wall. I looked at the reflection vectors for bouncing thread, but I don't understand it. Maybe I just need a basic vecor tutorial? I've read about how you add and subtract vectors, but am not sure how to apply it. [edited by - evilclown on May 5, 2002 3:40:45 PM]

Share this post


Link to post
Share on other sites
Advertisement
my thread below has confused me immensly, but I think I''m making some slow progress. Anyway, to get the ball bouncing off the walls you have to negate the appropriate vector element. eg if it touches the top or bottom, negate the Y component of your movement vector, if it hits the left or the right then negate the X component. Compared to the paddle that bits a doddle!!

Hope that helps get you started. Is it a breakout type game your doing by any chance?

Share this post


Link to post
Share on other sites
if it hhits the left or right side multiply the x component by negative 1 so it starts moving in opposite direction same for y component up or down

Share this post


Link to post
Share on other sites
if it hhits the left or right side multiply the x component by negative 1 so it starts moving in opposite direction same for y component up or down

Share this post


Link to post
Share on other sites
not quite sure, but I would imagine the x = -x version would have to create a new variable, hence a call to a constructor at the very least. Therefore probably slower, but I''m just guessing...

Share this post


Link to post
Share on other sites
quote:
Original post by evilclown
what would be faster for the computer?

x *= -1;

or

x = -x;


Go for the second, just because it''s clearer. It does NOT make a temporary variable.

Actually, any compiler with any optimization whatsoever will make both of those the same machine code. Don''t sweat it; you can profile later.

Share this post


Link to post
Share on other sites
dont care about _THAT_ bit of code..
the compiler will optimice it anyways
and do you think that this will be a speedloss if a normal pc can do this up to 2.4billion times a second today. i dont think you have 10million paddles..

"take a look around" - limp bizkit
www.google.com

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!