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: Intermediate

Continuous Collision Detection (CCD)

Contents

  • What is Continuous Collision Detection (CCD)?
  • How do you turn CCD on?
  • When should I turn CCD on?

 

What is Continuous Collision Detection?

The physics engine in Stencyl (Box2D) handles collisions between objects, which prevents your characters from walking through walls.

In some cases, however, fast-moving actors, such as bullets or falling objects, can pass right through a wall or floor. That's where CCD comes in.

In the physics engine, collisions are detected every frame at the point where the object moves to. If the object moves into another object or a tile (as illustrated by the purple area in the image), then the physics engine pushes it back to where the collision happened initially.

Succesful-collision-detection

You never actually see what happens in the middle image, but that is what is happening behind the scenes. On the other hand, if you have a ball that is moving really quickly towards a platform, then it's possible that the two objects never actually intersect and the engine doesn't detect the collision. When this happens, the ball will pass right through. This is called tunnelling.

collision-detection-tunnelling-example

The way physics engines generally solve this problem is to allow for what is called Continuous Collision Detection (CCD).

What this means is that when an object moves during a frame, it actually checks all the positions between where it started and where it ended up. If the engine detects any objects in this path, then the engine detects a collision. This is shown in the next image, where the purple area is the object's path.

Continuous-collision-detection

As you might imagine, checking that entire area is more processor intensive than checking a single spot every frame. This is why Continuous Collision detection is off by default, and should only be turned on if needed. Leaving it on if you really don't need it, especially with large numbers of objects, will slow your game down.

 

How do I turn it on?

1) Use the Actor Physics Setting

Located under the Physics > Advanced page for an Actor.

stencyl-enable-continuous-collision-detection-button

 

2) Use the Block

The block's located under Actor > Properties > Misc

stencyl-design-mode-continous-collision-detection-block

 

When should I use it?

This is a bit trickier. As mentioned above, enabling Continuous Collision Detection can strain on your processor (particularly on mobile), so you should use it sparingly. You should only enable it on fast-moving objects, such as bullets or things that are falling.

If you see objects passing right through walls or floors, and you checked that their collision shapes are in order, then this is something to try.

You can test whether enabling continuous collision detection is necessary by first slowing down your object and seeing whether it collides as you'd expect. If it collides with walls when moving slowly, but not when moving quickly, then you need to enable it.

Tips and Tricks

Preventing a Framerate Drop

When you have a large number of Actors on screen that are constantly colliding with one another, or with tiles, your came could experience a framerate drop. The way to resolve this issue is to turn off Continuous Collisions for each Actor Type (on their respective Physics pages) and to add a code block with the code shown below to any movement Behaviors your Actor Types are using.

box2D.dynamics.B2World.m_continuousPhysics = false;

Summary

  • Continuous Collision Detection (CCD) prevents cases of small, fast-moving actors from traveling through thin walls.
  • CCD impacts performance. Use only on the actors that need it.

 

Challenge: Replicate the "tunneling" problem

Want to test your complete understanding of CCD?

Create a game that replicates a scenario that requires CCD to solve. Think about the conditions required for "tunneling" to happen.

 



Last Updated: 2013-01-29 by Jon

12742 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!
6 Comments
Korayementality
Here's a tip for all of you guys who still have problem with the CCD..(it may help in SOME cases not ALL)

My problem was that I was making a Mario-like game, where at points you had to jump over the baddies to kill them. And there was always a chance that you get killed before you kill the baddie.

The reason for that was cause stencyl detected the baddie as a platform that I was stepping on, so it treats my actor as if it was on the ground and colliding with the baddie normally.

BOTTOM LINE: To solve it, I had to set the collisions on the baddie to "Is Sensor" located in the collisions tab.

This may or may not solve your problem, so go ahead and try it.

0 3 months, 3 weeks ago
redfoxwaffle
my actors still go through the tiles, i wonder why?
0 6 months, 2 weeks ago
Leaufai
This is Level: Beginner, even though it's in the Advanced section. Shouldn't it be Intermediate like the other Advanced topics?
0 9 months, 2 weeks ago
72master
and what do you do if that doesn't work and slowing it down didn't help either and all the collision groups are correctly set. is stencyl just being buggy or what because this is driving me mad
1 10 months, 5 days ago
thekidinboston
YES!! Thank you.
0 1 year, 3 months ago
fulvio
Brilliant, thanks for that tip.
0 1 year, 7 months 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.