Vectors bouncing
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]
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?
Hope that helps get you started. Is it a breakout type game your doing by any chance?
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
[size=2]aliak.net
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
[size=2]aliak.net
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...
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.
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
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
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement