SFML community forums

Help => General => Topic started by: ravenheart on September 23, 2008, 07:40:02 pm

Title: Collision per vectors ?
Post by: ravenheart on September 23, 2008, 07:40:02 pm
hello again =)

i have a breakout and now i want to now if the ball hits a rectangle, then it should bounce off

is there any possibility to manage that per normals- vectors?

or are if clauses better?
Title: Collision per vectors ?
Post by: Wizzard on September 24, 2008, 01:47:26 am
Try having a look at this (http://www.gamedev.net/reference/articles/article735.asp). Of course there is other ways to do collision detection, but this is by far the easiest to implement.
Title: Collision per vectors ?
Post by: zarka on September 24, 2008, 09:30:33 am
make a google search for "circle rectangle intersection" or something similar and you should probably get some good results :) but for a breakout clone i think rectangle-rectangle intersections will suffice. And they are dead simple to do :)
Title: Collision per vectors ?
Post by: ravenheart on September 24, 2008, 10:52:55 am
and how do i do it when i want to manage many bricks that disappear when hit?

something like a bool exists?
Title: Collision per vectors ?
Post by: zarka on September 24, 2008, 11:16:06 am
Quote from: "ravenheart"
and how do i do it when i want to manage many bricks that disappear when hit?

something like a bool exists?


yeah that will work :). you could also look into managing your objects dynamically in some way this would probably be a "nicer" solution start with checking out std::vector.
Title: Collision per vectors ?
Post by: ravenheart on September 24, 2008, 12:12:39 pm
and how can i get the direction from where my ball came? only collision is not enough, i need to know where the ball hit ,
my bat can be moved up down left and right, so i need to know in what direction the ball should bounce
Title: Collision per vectors ?
Post by: zarka on September 24, 2008, 03:14:04 pm
Quote from: "ravenheart"
and how can i get the direction from where my ball came? only collision is not enough, i need to know where the ball hit ,
my bat can be moved up down left and right, so i need to know in what direction the ball should bounce



prev_position - cur_positon = direction_vector

a good way of defining how the ball should move would be a direction vector and a speed value. then you just have to read up on some vector math and be ready to go :)