9 – Collisions in GameSalad

In this tutorial, we’ll take a look at collisions in GameSalad.  Collisions are a key aspect of nearly every game you may wish to make, as they don’t just determine what happens when one item runs into another, but also when two items simply need to contact one another or rest upon one another.

The primary behavior that affects collisions is the “Collide” behavior.  When placed on any actor, the Collide behavior allows you to specify another actor with which the behavior-bearing actor will collide.  In other words, if Actor “Land” has the Collide behavior, and you specify the Actor “Building”, Land will collide with Building (and vice versa) even if the Building Actor has no Collide behaviors.  Even if neither actor is meant to move, the “Collide” behavior is often very useful for two actors that will rest on one another (say, a building sitting on land) in order to just make sure everything stays where it is supposed to be, and doesn’t fall off the scene due to gravity or another movement behavior.

To use the “Collide” behavior, simply drag it into the behavior listings for any actor, and specify the corresponding actor (or groups of actors, if you’re using Tags; we’ll discuss these in a later tutorial) with which your actor should collide.

Another way in which collisions come into play with GameSalad is in your rule specifications.  You’ll notice when you create a new rule that you can set conditions or requirements for the activation of a behavior, and that one of these conditions is when an actor “overlaps or collides” with another actor.  This will allow you to condition events upon two actors contacting one another – for instance, if they are set to collide with each other per the Collide behavior instructions above, a rule conditioned upon this event would activate upon the moment of that collision.  If they are not set to collide with the Collide behavior, they will overlap one another and also activate the rule.  Using a rule like this is a great way to have an actor destroy itself upon collision with another actor, for instance – simply drag the “destroy” behavior into a rule, and change the conditions of the rule to say “Actor Receives Event – Overlaps or Collides – with actor _______.”

Since nearly all games rely upon actors moving about the scene and interacting with one another, the Collide behavior and the collision condition in your rules will get used in nearly every game you make.

This concludes our “Getting Started” tutorials.  With a little art and some experimentation, you should be able to go out and start making games.  Or, if you would like more information, check out our “Making It Better” tutorials!  When you’re ready to put a game out there, we’ve also provided comprehensive guides on both iOS and Android publishing.