Artifact blog #1 Collision

Hi. Time to start writing about the game design course!

This past week Hampus and I worked on understanding and using the collision in Box2D.  Box2D is a physics engine that works with C++, and while only using it for the collision might seem a bit of an overkill Box2D has such a great variety of usage that learning it now can pay off in later projects as well. As far as collision goes here’s a list of the features Box2D has:

  • Continuous collision detection
  • Contact callbacks: begin, end, pre-solve, post-solve
  • Convex polyons and circles.
  • Multiple shapes per body
  • One-shot contact manifolds
  • Dynamic tree broadphase
  • Efficient pair management
  • Fast broadphase AABB queries
  • Collision groups and categories

What makes Box2D so easy to use is the fact that as long as the objects you create are in the same “world”, they will collide with each other. Or rather, in Box2D you make the hitbox for objects and then in SFML (or another library of your choice) you make a the actual object and have it share the same position as the hitbox. Then you just make one of them move (in our case the hitbox) and have the other one follow by always updating the position. The hard part is implementing Box2D in an onworking project as I will come to shortly.

We began reading the documentation that came with Box2D and focusing on the parts about collision, on Tuesday we began trying to include the files into a project and try things out. Including it in an empty project on its own is just as easy as SDL or SFML, but together with something else is where the issues begin. SFML doesn’t particularly like Visual Studio 2013, but Box2D doesn’t particularly like VS 2012. We tried using CMake to build Box for 2012 but that didn’t achieve anything, no matter how much the tutorial tried to convince me.

At Thursday we had a meeting with our mentor from the 3rd year, and he thought it would be easier to just make the collision ourself rather than trying to learn Box2D. Since he’s a 3rd year we took his word for it even though we didn’t really get why it would be easier to do so, and I began working with the collision from a previous project and see if it could work out here as well. Hampus on the other hand felt that we had spent too much time on Box2D to give it up and so he continued tempering with it. We thought that if we split up and tried different things we’d simply use the collision from whoever got things to work first. And that was Hampus. On Friday we had a ball dropping down on an invisible square and colliding with it, and during the weekend Hampus got chains to work as well. Chains is a way to make collision work between objects and walls. You simply set out the coordinates for every point/edge in the wall and the chains will link them to each other automatically.

chains

 

^click

So as of right now we understand how to create objects and chains, and our next artifact is to implement it in the project.