Skip to content

Patrol

Walks back and forth with no code, turning at walls, (optionally) at the edges of what it stands on, and at Left and Right when they’re set: a platformer’s basic enemy. Needs a Body and a collider. With a Chase too, it patrols until it spots its target. The Scene view draws its route.

Requires: Body; Collider

Works with: Chase (patrols until it spots its target)

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • speed: a number = 2. World units per second. (Field: a number.)
  • goingLeft: true or false = false. Which way it’s walking. Tick it to start off walking left; it changes as it turns. (Field: on or off.)
  • turnAtEdges: true or false = true. Turn round rather than walk off the edge of a platform. (Field: on or off.)
  • flipSprite: true or false = true. Flip its sprite to face the way it walks (art should face right). (Field: on or off.)
  • left: a number = 0. How far left of where it’s placed it walks before turning, in world units. 0 walks on until a wall or an edge. (Field: a number.)
  • right: a number = 0. How far right of where it’s placed it walks before turning, in world units. 0 walks on until a wall or an edge. (Field: a number.)
  • walked: a number = 0. How far right of where it was placed it is (left is below zero), which Left and Right are measured from. The game keeps it up to date as it walks or is knocked about; set it to start part of the way along. (Field: a number.)

Scripts use it as Patrol: its methods, events and values that aren’t saved with the scene.