Building the LEGO Security Actor Behaviors

For our LEGO Security actor, we want his behavior to be a bit unpredictable so that the actor shoots and jumps at random intervals.

Adding Gravity and Jump Behaviors Using Shortcuts

The first thing we'll do is reuse the built-in "run and jump by pressing keys (side view)" shortcut we showed earlier in "Adding Main Actor Behaviors Using Shortcuts," to create the gravity and jumping behaviors automatically. We're doing this to save time and avoid the errors that might be introduced when manually building these behaviors. Since the Security actor will have random motion and not keyboard-based motion, delete the RunLeft and RunRight behaviors. With those deleted, the LEGO Security actor should only have the behaviors listed in Figure 2-42.

Using shortcuts to speed up the addition of common behaviors

Figure 2-42. Using shortcuts to speed up the addition of common behaviors

Setting a Random Jump Behavior

The one change we'll want to make for these prebuilt behaviors is the Jump behavior's event, which is currently mapped to the spacebar. Click on the Jump behavior's event to change it from a keyboard event to a random time interval between 2 and 8 seconds, as shown in Figure 2-43. As you can imagine, this will make our Security actor randomly jump in the air every 2 to 8 seconds.

Setting an event's behavior to fire at a random time interval

Figure 2-43. Setting an event's ...

Get Coding4Fun now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.