Archived

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

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.

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 on other sites
http://www.gamasutra.com/features/20020118/vandenhuevel_03.htm

Share on other sites
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 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 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 on other sites
what would be faster for the computer?

x *= -1;

or

x = -x;

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 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 on other sites
oops, I stand corrected

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

• 10
• 17
• 9
• 14
• 41
• Forum Statistics

• Total Topics
631067
• Total Posts
2997734
×