SFML community forums

Help => General => Topic started by: David on June 16, 2011, 02:16:04 pm

Title: Collision Optimization
Post by: David on June 16, 2011, 02:16:04 pm
Hey!

I was playing around with collisions the other day (finally figured it out coming from a scripting background) and noticed that other engines such as Box2D and Chipmunk also support collision

My game is going to be tile-based (bounding box), and I need to know which collision is better: Checking the coordinates or using an engine's collision tests?
Title: Collision Optimization
Post by: Groogy on June 16, 2011, 02:19:24 pm
Box2D and Chipmunk is more for simulating some kind of physics if you ask me. If you only need collision detection and not forces then do it yourself is my opinion. Also those engines do use bounding boxes too, among other things.
Title: Collision Optimization
Post by: David on June 16, 2011, 02:28:50 pm
Quote from: "Groogy"
Box2D and Chipmunk is more for simulating some kind of physics if you ask me. If you only need collision detection and not forces then do it yourself is my opinion. Also those engines do use bounding boxes too, among other things.


This also goes with another question I had in mind: Whether I should use actual physics or not (I'm making a platformer), but that's for another day
Title: Collision Optimization
Post by: Dimple on June 17, 2011, 01:54:16 am
The code will probably run faster if you implement it yourself (assuming you won't mess up :P). On the other hand, if you implement it yourself, you have to prevent tunneling yourself (if it is an issue), you have to figure out how to respond to the collision etc. I would do it myself if I was you, unless I needed to simulate physics.
Title: Collision Optimization
Post by: Nexus on June 17, 2011, 02:01:06 am
I think it depends on the complexity. For a simple rectangular collision, it's not worth to use an external library, but as soon as collisions get more complex and are of a common type, I would rather use something existing than reinvent the wheel. Libraries that focus on such functionality also tend to be more optimized and bug-free than own implementations.
Title: Collision Optimization
Post by: David on June 17, 2011, 02:02:58 am
Quote from: "Dimple"
The code will probably run faster if you implement it yourself (assuming you won't mess up :P). On the other hand, if you implement it yourself, you have to prevent tunneling yourself (if it is an issue), you have to figure out how to respond to the collision etc. I would do it myself if I was you, unless I needed to simulate physics.


Yea, that's what I thought, but I also thought that since it's an engine that supports collision, it should be very optimized
Title: Collision Optimization
Post by: OniLinkPlus on June 17, 2011, 06:26:21 am
If it's axis-aligned rectangles, a simple BBox test will suffice. If it's rotated or any convex polygon, use the Separating Axis Theorem. If there are concave polygons (unlikely), triangulate then use the Separating Axis Theorem.