Tutorial 5: Collision Detection

This is the 5th Tutorial in the pre-ludum dare series that I’ve been putting together. Find tutorial 4 here.

This tutorial introduces the concept of collision detection. The zip file with the code in can be found here. The example posting can be found here.

Concept of Collision Detection

So why do we need things to collide? Well if we don’t check to see if two things have collided then we don’t really have much of a game. We’d fall through floors in platformers, no-one would be able to shoot us and we’d be able to walk through walls in first person shooters. So with our ateroids clone (as it’s shaping up to be) we need to calculate whether the centre of the objects is too close together.

We can do this by using¬†FiltoidCollisionCheck() in FiltoidUtils.js. We can assign this to the player object and then pass in any enemy objects then we can use their locations and sizes to calculate this. The function calculates the distance between the two points and then if this distance is less than the two sizes then we shall not let the movement forward occur and (in this case) we’ll reset the spacecraft to the start point (this will look a little like death).

In the next tutorial we’ll make a collision manager…

Posted in Games, Ludum Dare
0 comments on “Tutorial 5: Collision Detection
1 Pings/Trackbacks for "Tutorial 5: Collision Detection"
  1. […] tutorial 5 (which can be found here). We looked at how to calculate a circular collision field. But this isn’t that practical […]

Leave a Reply