SFML community forums

Help => General => Topic started by: The Strangled Bear on March 15, 2013, 04:29:35 pm

Title: Collision detection between a vertex and a sprite (or collision box).
Post by: The Strangled Bear on March 15, 2013, 04:29:35 pm
We are on a game project and we are trying to figure out how to check if a vertex line collides with a sprite.

The vertex is supposed to go from the player position to a position determined by mouse (this part is all done), and then check if certains object collides with the line (this is where we get stuck). We would show some source code, but we basically don't have any code to show, since we don't really know how to approach this.
Any help would be apprechiated!
Title: Re: Collision detection between a vertex and a sprite (or collision box).
Post by: eXpl0it3r on March 15, 2013, 04:50:10 pm
Collision detection can be quite a complex or at least confusing topic, fortunately you guys are not alone, but there are thousands of other people who had the same problem in the past, that's why you can find a lot with Google. ;)

One result (http://gamedev.stackexchange.com/questions/12106/line-rectangle-collision-detection-and-response) after 1min searching seems promising, although the code is only available if registered, I think, but it's explained quite well.

Some keywords to search for:

But keep in mind, you'll need some mathematical understanding in most cases. ;)
Title: Re: Collision detection between a vertex and a sprite (or collision box).
Post by: Nygarda on March 18, 2013, 10:24:01 am
Thank you for the link eXpl0it3r and the keywords.

I had the same problem, thanks to the post I now understand what I actually want to do and share the knowledge idea. Instead of checking collision on the line you could use a sprite with a specific length and then rotate is relative to the position of the mouse, and use .intersect or .contains when it collides with an object.

Hope this helped.
Best regards Nygarda.