Patrol
namespace Griff.Scenes;
public sealed class Patrol : ComponentWalks 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.
Properties
Section titled “Properties”FlipSprite
Section titled “FlipSprite”public bool FlipSprite { get; set; }Flip its sprite to face the way it walks (art should face right).
GoingLeft
Section titled “GoingLeft”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.
TurnAtEdges
Section titled “TurnAtEdges”public bool TurnAtEdges { get; set; }Turn round rather than walk off the edge of a platform.
Walked
Section titled “Walked”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.
Methods
Section titled “Methods”public void Turn()Turns round to walk the other way.
Events
Section titled “Events”Turned
Section titled “Turned”public event Action<Patrol>? TurnedRaised when it turns round.