Skip to content

FirstPersonMovement

namespace Griff.Modules.FirstPerson;
public sealed class FirstPersonMovement : Component

First-person controls with no code: W and S (or up and down) walk, A and D strafe, the left and right arrows turn, and the mouse looks around once the game is clicked (Esc gives the mouse back). Holding Dash (Left Shift) runs. On a controller the left stick walks and strafes and the right stick turns. It turns the entity’s Rotation Z, the way a FirstPersonView looks. Needs a Body and a collider (a circle slides along walls best).

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

public float Acceleration { get; set; }

How quickly it gets up to speed and stops, in units per second per second. 0 is at once.

public bool Controllable { get; set; }

Untick it (from a script, in a cutscene) to ignore the player’s input. Its Focus action ticks it and unticks it on everything else the player plays (a board, another character), and back.

public Vector2 Facing { get; }

The way it’s facing across the floor, as a unit vector.

public bool LookUpDown { get; set; }

Let the mouse (and the right stick) look up and down a little, as well as turn.

public bool MouseLook { get; set; }

Turn with the mouse. The game takes the mouse when it’s clicked, and gives it back with Esc.

public float MouseSensitivity { get; set; }

Degrees turned for each pixel the mouse moves.

public float Pitch { get; set; }

Degrees it’s looking up (positive) or down (negative), with LookUpDown.

public float RunSpeed { get; set; }

Speed while Dash is held. The same as Speed for no running.

public float Speed { get; set; }

Walking speed, in world units per second.

public float StepLength { get; set; }

World units between footsteps.

public string? StepSound { get; set; }

A footstep sound, played every StepLength units walked.

public float Stride { get; }

How fast it’s walking, from 0 (standing) to 1 (full speed): for the view’s bob.

public float TurnSpeed { get; set; }

Degrees per second the arrow keys (and the right stick, all the way over) turn it.