Making Actors Move Along Paths

*Requires SCI Studio 2.11 or higher.

Most likely in your game you will need to have actors moving. This is simply done by setting the actor's motion.

Getting Started

Open your game in the resource explorer and select "Resource"->"Add Sample"->"View"->"Brian" from the menu.

Save it to your game as view.001.

You can obviously use this in any script, but for demonstration purposes, open up the game's "rm001.sc" script.

Since the ego is an actor, everything in this lesson can be applied to it as well. However, to keep things simple, we will create another actor. Scroll down to the end of the script and add the following lines of code:

(instance aMan of Act
  (properties
    y 170
    x 190
    view 1
  )
)

This simply creates an actor which uses view.001 and positions it at (190,170).

Next, go to the game's instance, then scroll down to the bottom of the init method.

Set up the actor with the following lines of code:

(aMan:
  init()
  setCycle(Walk)
)

This simply initializes the actor, then sets it's cycle to Walk. If the cycle wasn't set, it would just drag across the screen. It's now ready for it's movement to be set up.

Simple Actor Movement

Setting up an actor to move from it's current position to another is very simple. All you need to do it call it's setMotion() method, and set it's motion to MoveTo. This method takes three additional parameters: the X coordinate, the Y coordinate, and the room script. The X is of course, the amount of pixels from the left of the screen the actor will be positioned, and the Y being the amount of pixels from the top. The room script is used to trigger an event. Just set it to the current room script.

To implement it, you can simply adjust the initialization of the actor and add a MoveTo setMotion:

(aMan:
  init()
  setCycle(Walk)
  setMotion(MoveTo 180 150 RoomScript)
)

The actor is now set to move to the coordinates (180,150).

That's all there is to it!

Moving Actors Along Paths

Moving actors along paths requires the DPath motion. You simply call the setMotion method and set the motion to DPath. It takes an unlimited amount of parameters. You just add the X,Y coordinates which is should move.

To implement it, you can simply adjust the initialization of the actor and add a MoveTo setMotion:

(aMan:
  init()
  setCycle(Walk)
  setMotion(
     DPath
     180 150
     240 100
     280 160
     180 150

  )
)

This sets up the actor to move to (180,150), then up to (240,100), then down to (280,160), then back to it's starting position, (180,150).

Compile and run and you'll see the actor move just like that!

Setting An Actor's Motion Anywhere

In the preceding examples, the actor's motion was set in the init() method. However, it can be called from anywhere in the script.

Here's an example of using it anywhere:

(aMan:setMotion(MoveTo 180 150 RoomScript))

That sums up actor movement! For more complex movement, have a look at the chapter Moving Actors and Triggering Events.

Good luck!

Back To The Table of Contents