Skip to content

walk

The walk component defines the movement and animation behavior of a character in a game. It allows customization of walking, sprinting, and turning styles, including key bindings and speed settings. The component also supports auto-walk and point-and-click movement options.

⚠️ PHYSICS ENGINE

The walk component rely on the Ammo.js physics engine. Ensure that Ammo.js is installed in your project for proper functionality.

How it works

  1. Set the walkClipName and idleClipName properties (or sprintClipName if you enabled sprinting). Without the correct animation names, the character will not move.
  2. To enable sprinting (disabled by default), set sprint to true.
  3. Set your turnType (default: smoothTurn). Learn more about turn types here.
  4. To make the character move automatically without user input, set autoWalk to true. Learn more about autoWalk here.
  5. To control the character with your mouse, set targetWalk to true. Learn more about targetWalk here.
  6. Customize movement by adjusting the speed, sprintSpeed, keyUp, keyDown, keyLeft, keyRight, and sprintKey properties.

Example

Use the mouse to rotate the scene.

Props

PropertyTypeDefaultDescription
walkClipNamestringWalkName of the animation clip used when the character is walking.
idleClipNamestringIdleName of the animation clip used when the character is idle.
sprintClipNamestringGallopName of the animation clip used when the character is sprinting.
turnTypeenum(smoothTurn, stepTurnCardinal, stepTurnDiagonal)smoothTurnDefines the walking mode and how the player turns and moves.
autoWalkbooleanfalseIf true, the player will automatically start walking forward without input.
targetWalkbooleanfalseIf true, enables point-and-click movement: the character walks toward the location where the player clicks.
speedfloat5.0Defines the player's base walking speed.
rotationSpeedfloat90.0Defines the turning speed for smoothTurn mode.
sprintbooleanfalseIf true, the player can sprint when holding the sprintKey, increasing their speed to sprintSpeed.
sprintKeystringshiftKey used to sprint with the character.
sprintSpeedfloat8.0Defines the sprinting speed when the sprint mode is active.
keyUpstringwKey used to move the character forward.
keyDownstringsKey used to move the character backward.
keyLeftstringaKey used to move the character left.
keyRightstringdKey used to move the character right.

turnType

  • smoothTurn: The player turns smoothly while the key is held. The player can move while turning. You can adjust the speed of rotation by the rotationSpeed property.
  • stepTurnCardinal: When pressing a key, the player instantly turn 90° in the selected direction (toward, backward, left, or right) and then moves. It enables 4-directional movement.
  • stepTurnDiagonal: Works the same way as stepTurnCardinal, but also allows movement in a diagonal directions (↗, ↘, ↙, ↖) by turning 45° before moving. It enables 8-directional movement.

autoWalk

If the autoWalk property is set to true, the player will automatically start walking forward without input. It works with all turn types.

targetWalk

If the targetWalk property is set to true, it enables point-and-click movement: the character walks toward the location where the player clicks. The rotationSpeed property is set automatically and cannot be changed.