Skip to content

Follow

namespace Griff.Scenes;
public sealed class Follow : Component, IViewFocus

Moves the entity after another one, smoothly: a camera after the player, a pet after its owner. No code needed: put it on the camera and name the Target. With StayInside, a camera never shows past the edges of the level. Applied while the game runs, after physics, so it follows where things ended up this frame.

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

public Room? CurrentRoom { get; }

The Room a camera is keeping to, in place of StayInside; set by the game as the target moves from room to room.

public Vector2 DeadZone { get; set; }

A box around the follower, in world units, that the target can move about in without the follower moving. (0, 0) follows every step; something like (2, 1) keeps a platformer’s camera still for small hops.

public bool IsChangingRoom { get; }

True while the camera is sliding over to a new room.

public float LookAhead { get; set; }

Seconds of the target’s movement to look ahead by, so a camera shows more of where the player is heading.

public Vector2 Offset { get; set; }

Where to sit relative to the target, in world units, e.g. (0, 2) to see more above a platformer’s hero.

public float Smoothing { get; set; }

How quickly it catches up: higher is snappier, 0 sticks exactly to the target.

public string? StayInside { get; set; }

The name of an entity whose area the follower stays inside: a tilemap’s grid, a box collider, or a sprite. On a camera the whole view stays inside, so the game never shows past the level’s edges.

public string? Target { get; set; }

The name of the entity to follow, e.g. “Player”.

public Entity? TargetEntity { get; set; }

The entity being followed. Set it from a script to follow something without looking it up by name.

public void Advance(float seconds, float viewAspect, float? realSeconds = default)

Moves toward the target by seconds of smoothing. Called by the game after physics.

  • viewAspect: The view’s width over its height, for keeping a camera’s view inside StayInside.
  • realSeconds: Real time passed, for sliding between rooms while the game is held still; seconds if not given.
public static Box? AreaOf(Entity entity)

The world-space box an entity covers: its tilemap’s grid, else its box collider, else its sprite.

public void Snap()

Jumps straight to the target next time instead of gliding over, e.g. after a teleport or a respawn (doors and checkpoints do this by themselves).