Skip to content

Patrol

namespace Griff.Scenes;
public sealed class Patrol : Component

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.

This is a component: its saved properties are on its component page.

public bool FlipSprite { get; set; }

Flip its sprite to face the way it walks (art should face right).

public bool GoingLeft { get; set; }

Which way it’s walking. Tick it to start off walking left; it changes as it turns.

public float Left { get; set; }

How far left of where it’s placed it walks before turning, in world units. 0 walks on until a wall or an edge.

public float Right { get; set; }

How far right of where it’s placed it walks before turning, in world units. 0 walks on until a wall or an edge.

public float Speed { get; set; }

World units per second.

public bool TurnAtEdges { get; set; }

Turn round rather than walk off the edge of a platform.

public float Walked { get; set; }

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.

public void Turn()

Turns round to walk the other way.

public event Action<Patrol>? Turned

Raised when it turns round.