Follow
namespace Griff.Scenes;
public sealed class Follow : Component, IViewFocusMoves 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.
Properties
Section titled “Properties”CurrentRoom
Section titled “CurrentRoom”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.
DeadZone
Section titled “DeadZone”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.
IsChangingRoom
Section titled “IsChangingRoom”public bool IsChangingRoom { get; }True while the camera is sliding over to a new room.
LookAhead
Section titled “LookAhead”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.
Offset
Section titled “Offset”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.
Smoothing
Section titled “Smoothing”public float Smoothing { get; set; }How quickly it catches up: higher is snappier, 0 sticks exactly to the target.
StayInside
Section titled “StayInside”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.
Target
Section titled “Target”public string? Target { get; set; }The name of the entity to follow, e.g. “Player”.
TargetEntity
Section titled “TargetEntity”public Entity? TargetEntity { get; set; }The entity being followed. Set it from a script to follow something without looking it up by name.
Methods
Section titled “Methods”Advance
Section titled “Advance”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 insideStayInside.realSeconds: Real time passed, for sliding between rooms while the game is held still;secondsif not given.
AreaOf
Section titled “AreaOf”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).