Skip to content

FirstPersonMovement

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).

Part of the First Person module: First-person games: the world seen through the player’s eyes from a flat map (FirstPersonView), walking and turning (FirstPersonMovement), weapons, billboards and solid blocks, and the Shooter template.

Requires: Body; Collider

Works with: Weapon (shoots where it looks)

Takes the player’s input only while it has focus (its Controllable): its Focus action hands it the input and takes it from everything else the same player plays.

In a network game, the player it moves for runs it on their own machine and sends where they are.

Each is listed as its key in the scene file and the MCP tools, then its kind of value, its default and what it does.

  • speed: a number = 4. Walking speed, in world units per second. (Field: a number.)
  • runSpeed: a number = 7. Speed while Dash is held. The same as Speed for no running. (Field: a number.)
  • acceleration: a number = 40. How quickly it gets up to speed and stops, in units per second per second. 0 is at once. (Field: a number.)
  • turnSpeed: a number = 150. Degrees per second the arrow keys (and the right stick, all the way over) turn it. (Field: a number.)
  • mouseLook: true or false = true. Turn with the mouse. The game takes the mouse when it’s clicked, and gives it back with Esc. (Field: on or off.)
  • mouseSensitivity: a number = 0.15. Degrees turned for each pixel the mouse moves. (Only used when mouseLook is on.) (Field: a number.)
  • lookUpDown: true or false = true. Let the mouse (and the right stick) look up and down a little, as well as turn. (Field: on or off.)
  • controllable: true or false = true. 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. (Field: on or off.)
  • stepSound: text = null. A footstep sound, played every StepLength units walked. (A sound in Assets, e.g. “Sounds/hit.wav”.) (Field: a sound.)
  • stepLength: a number = 1.6. World units between footsteps. (Only used when stepSound is set.) (Field: a number.)

What anything can make it do with no code: a Trigger’s do when its message arrives, a Contraptions Wire’s input as its signal comes on, a script’s Game.Do(entity, “Name”).

  • Focus. Gives its entity the player’s input: whatever there and inside it has focus, and everything else the same player plays loses it (a platformer’s player stops on the arrow keys while a board takes them).

Not saved with the scene; scripts read them, and entity_get shows them as live while the game plays.

  • pitch: a number. Degrees it’s looking up (positive) or down (negative), with LookUpDown.
  • facing: [x, y]. The way it’s facing across the floor, as a unit vector.
  • stride: a number. How fast it’s walking, from 0 (standing) to 1 (full speed): for the view’s bob.

Scripts use it as FirstPersonMovement: its methods, events and values that aren’t saved with the scene.