Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Beginner

Collisions & Groups

Contents

  • Collisions are Automatic
  • Groups
  • Shapes
  • Sensors
  • Handling Collisions
  • More Collision Handling (Sides, Groups, Points)


Collisions are Automatic

Because Stencyl is powered by Box2D, collisions happen automatically, as if every object existed in “real-life.” For the default cases, no action is required on your part to make collisions happen.

stencyl-ragdoll-demo

 

Groups

However, what if you only want certain collisions to happen? For example, if any enemy shoots a bullet, the bullet should only collide with the player, not other enemies.

stencyl-collision-groups-diagram

To do this, you have to set up Groups.

Groups are arbitrary collections of Actors. Groups tend to be named after certain classes of Actors, such as “Players” and “Enemies.”

stencyl-players-enemies-collision-groups-pic

Collisions happen between groups that are set up to collide with each other. Conversely, collisions are ignored between groups that are not set up to collide with each other.

 

How To: Setting up Groups

You can set up Groups in the Settings dialog. Click the Settings button to open the dialig.

Settings Button

Next, click the Groups button (shown below) and you'll see a dialog that shows the Collision Groups in your game, the green Create New button that lets you make a new Group, and other settings.

Collision Groups Dialog

There are fields for editing the name, description and the other groups it collides with.

(Note: In this picture, Players collide with Tiles.)
 

Default Groups

Every Stencyl game starts out with a default set of Groups to help you get started.


These groups have a lock next to them. Default groups cannot be edited or removed.
  • Players
  • Tiles
  • Doodads (Scenery)
  • Actors
  • Regions

By default, Doodads and Regions never involve physical collisions. They may be useful if you want a quick way to designate an actor as "non-colliding"

 

How To: Assigning Actors to Groups

You can set an Actor's collision properties, and specify the group it belongs to, in the Properties page of the Actor Editor.

stencyl-assign-actor-to-collision-group

 

Shapes

As we talked about in the Animations section, Actors can take on different Animation states. For each Animation state, the Actor can have different collision bounds.

For example, if a character is standing, he may be taller. If he’s ducking, he may be shorter.

squid-game-sprite

Stencyl supports 3 kinds of collision shapes: Boxes, Circles and Polygons. (For Polygons, only convex shapes are allowed!)

stencyl-collision-shapes-buttons

You can place an arbitrary number of these shapes, in order to form more complex ones.

stencyl-place-collision-bounds

(In this example, we’ve made an “L” shape using 2 boxes.)


Sensors

What if you want to detect collisions, without the shapes actually colliding? For example, in Tower Defense games, the towers shoot at targets that come into range.


You’d use Sensors to make this happen. Sensors are special kinds of shapes (a yes/no flag on any shape to be precise), in which an Actor does not physically collide with another Actor, but still detects the collision.

stencyl-collisions-sensor-option-pic

Just check this box in the right-hand pane of an Actor’s Collision Page to make a certain shape a Sensor.

 

Handling Collisions

Use Events to handle collisions. By "handling", we mean responding to collisions with logic. For example, if a Fireball crashes into Mario, Mario will die.

We support 6 kinds of Events in total.

stencyl-collision-events

Regardless of which Event you pick, you’ll typically see a block similar to this.

stencyl-design-mode-collision-event-block

1st actor always pertains to the first actor in the “sentence.” The same goes for the 2nd actor.

For example....

stencyl-design-mode-collision-event-block-example

Then, when this kind of collision happens, the 1st actor will refer to the Hero and the 2nd actor will refer to the Button.

stencyl-design-mode-collision-event-block-example-actor-references

Just in case, you didn’t know, you can drag the “1st actor” and “2nd actor” blocks out and use them anywhere within this event.

stencyl-design-mode-collision-event-dragging-actor-reference-blocks


More Collision Handling

For any kind of collision, you can check on 3 additional bits of info.

  • What side the collisions happened on
  • What Groups were involved
  • Collision Points (where the collisions happened)

 

Collision Sides

One point to watch out for is that collision sides are based on the rectangular, bounding box of the *shape* that collided, so if you used a circle or a polygon, pay attention to the results.

stencyl-design-mode-collision-side-blocks

Exercise: Stomping is one common use case for collision sides. Something is "stomped" if it was hit from the top. Can you think of other use cases for collision sides?

 

Groups for Colliding Shapes

stencyl-design-mode-collision-shape-group-block

What is this “colliding shape” business about? It stems from the ability to override an Actor’s default group on a per-shape basis, so that a particular shape can take on a different group.

stencyl-design-mode-changing-collision-group-for-shape

When working with the “Collision Group for colliding shape” block, be sure to compare groups directly, rather than comparing the textual name of the Group, which can lead to bugs and crashes.

stencyl-design-mode-collision-example-right-way
(This is the right way)

stencyl-design-mode-collision-example-wrong-way
(This is the wrong way, don’t do this!)


You can find all Group and Type “getter” blocks under Actor > Properties.

stencyl-design-mode-collision-group-getter-blocks

Note: The arrival of Events largely nullifies the need to check on specific groups or types after collisions. Why go through this effort when you can just say "when a (Fireball) collides with (Hero)..."?


Collision Points

Last but not least, you can grab exactly where collisions happened. This isn’t done very often, but it’s here in case you want to do any additional logic based on the collision location.

stencyl-design-mode-collision-points-blocks

 

Summary

  • Thanks to physics, collisions are automatic.
  • Groups help you filter out collisions by specifying who collides with who else.
  • Use sensors to detect collisions without the actor being “solid.”


Last Updated: 2012-07-24 by Ceric

25804 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!
7 Comments
speeddemon1234
This program is great compared to game maker 2.1 and The game factory 2 but there needs to be a way for you to get to the ALL the game attributes and be able to chose from one and not have so much grid and guessing to do on creating your games my game right now is set up but i have no idea how to get anything to happen in it.
0 6 months, 1 week ago
JamMan220
When I create collision groups for a certain object and then go to the objects collision page it only lists stencyl's already made collision groups and not the ones i have recently made. and I am stuck on what to do?
0 6 months, 2 weeks ago
ZephyrLightningheart
hmm. i did the the whole actor collides with actor but my player keeps passing right through the NPC.

Where should I should I put the collision even with "when actor 1 hit actor 2"? in both the player and NPC? or one of them?


0 8 months, 2 days ago
72master
so i don't need to worry about that last question i figured it out but i was wondering will stencyl ever allow you to make concave collision shapes?
0 9 months, 3 weeks ago
72master
so if my collision groups are set right but my main player keeps passing through my NPC's what should i do ? i mean i am pretty sure the collision is being recognized because i used one of the print blocks to make sure but i still pass right through help please :)
0 10 months, 1 day ago
srivello
I recommend the permanently renaming of the 'Doodads (Scenery)' group to 'Items' or something else.
0 11 months, 1 week ago
RuneWarden
How can I make it so that certains platforms only collide when a certain value is true?
0 1 year, 1 month ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.