Time for action – configuring the fruit as a sensor

The game file to import and load for this session is 5961_03_10.stencyl.

We'll start by setting up the banana actor as a sensor:

  1. Display the banana actor in the Animation Editor (click on the Dashboard tab, then Actor Types, and double-click on the Stencyl Book Banana thumbnail).
  2. Ensure that the Collision button is selected in the row of buttons at the upper-center of the screen.
  3. Click on the left collision circle on the banana so that it is selected.
  4. In the right panel, under the heading Physical Properties, click on the Is a Sensor? option so that a checkmark is shown as follows:
    Time for action – configuring the fruit as a sensor
  5. Click on the right collision circle on the banana so that it is selected.
  6. Click on the Is a Sensor? option so that a checkmark is shown.
  7. Click on the Physics button in the row of buttons at the upper-center of the screen.
    Time for action – configuring the fruit as a sensor
  8. Change the Affected by Gravity? setting to No.
  9. Test the game; make the monkey collide with the banana (it will run through it)!

What just happened?

We have changed the banana actor into a sensor; our game will still detect collisions between the banana and the monkey and cause a collision event, but the collision will not cause a physical reaction in the game. It's important to note that, because the banana has two collision shapes (two circles), we had to configure both of those shapes as sensors.

Because the banana is now a sensor, we also needed to change a physics setting so that it will no longer be affected by the scene's gravity. If we do not tell sensors to ignore gravity, they will fall straight through the tiles!

Don't these changes put us right back where we started? Before we created the Collectible collision group, the monkey ran straight through the banana actor, and that's what's happening now!

Although it looks like we have taken a step backwards, behind the scenes Stencyl is still detecting the collision, but instead of making the monkey bump into the banana actor, it is just sensing when the collision occurs and creating a collision event. This means that we can use or create behaviors that depend upon a collision being sensed between the monkey and the banana actors, and that's exactly what we need in our game!

Have a go hero

The game file to import and load for this session is 5961_03_11.stencyl.

We have only configured the banana to be a sensor, but we also have grapes, a melon, and a pineapple, which should also be configured in the same way, so go ahead and configure each of the fruit actors as sensors. Remember to change each actor's Affected by Gravity? setting to No so the actors don't fall through the tiles.

When this task has been completed, our monkey should be able to run through each piece of fruit without bumping into it!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.229.85