How do I make an actor behave randomly

Modified: 2008/04/30 12:40 by VinayD - Categorized as: Game Creator, How To Guides
Edit

Make an actor behave randomly

Basic Idea: Many times we want an action to be random. For example, a spaceship shooting down at a random interval. This can be done easily using the timer event. Define the shooting behavior triggered by a timer.

Sample Game: http://www.popfly.com/users/team/HowDoI-RandomBehavior

Details:
  • Define a shooting action
    • Trigger it on a timer
    • Make that timer's interval random

Actor->Behavior->Shoot->Event
Image

Random Timer event (Click the image to view full size)


Advacned Fun: You can use filters to introduce more complex game logic. Suppose you want spaceship to shoot randomly but only when it was fired upon. This is how you could do that:
  • Add a property to Spaceship
    • Call it ‘Shoot’
    • Set it 0
  • Add a property change event to the Spaceship
    • Triggered by a random timer
    • Changes ‘Shoot’ to 1
  • Add another property change event to the Spaceship
    • Triggered by a random timer
    • Changes ‘Shoot’ to 0
  • Add Shoot event to the Spaceshup
    • Triggered on collision
    • Filters on property ‘Shoot’ = 1

Privacy. Terms of Use. Trademarks.
ScrewTurn Wiki version 2.0.22. Some of the icons created by FamFamFam.