SFML community forums

Help => General => Topic started by: Loopback on April 26, 2014, 01:27:03 pm

Title: Collisions?
Post by: Loopback on April 26, 2014, 01:27:03 pm
Hi there! I'm having a bit of trouble trying to detect collisions (sprite with tmx::objects or other sprites). I know how to detect if its colliding but what I'd like to know is if f.e my character's sprite is colliding with an object at his right, left, bottom or down. How can I get it done? is there any way of doing it?

thank you very much for your help and hope I've explained my self properly
Title: Re: Collisions?
Post by: Ixrec on April 26, 2014, 01:45:29 pm
When a collision happens, get the centers of the two colliding objects (I'm assuming you know their positions and sizes), and compute the angle between them.  This will require basic trigonometry.  Standard functions like sin/cos are probably enough, though I think Thor has some useful vector arithmetic methods.
Title: Re: Collisions?
Post by: Loopback on April 26, 2014, 07:11:32 pm
Well, I think I can know its size by using the getAABB() function and position using getPosition();
I will give it a shot to see what can I get done
Title: Re: Collisions?
Post by: didii on April 28, 2014, 01:06:05 pm
There are a number of ways to do it.
The most difficult part is actually comparing rectangles with circles (or I've missed something). Since most objects can be reduced to a rectangle and circle (or combinations) it not too hard.

If you are working with tiles you can simply flag a tile as 'collidable' and when anything tries to move to its location, handle the collision.

Or you could use a library. Here (http://stackoverflow.com/questions/14915772/which-game-physics-engine-should-i-use) are a couple of them listed.