LogoLogo
  • Get Started
  • Getting Started
    • Initial Setup
    • Create Your First Game
    • API Reference
    • Build Your First World Map
    • Multiplayer Testing
    • Use Templates & Examples
    • Styling & Assets
      • Modeling Guidelines
      • Texturing Guidelines
      • Default Assets
  • Build Faster With AI Tools
  • SDK Guides
    • Assets
    • Audio & SFX
      • Audio Manager
    • Blocks & Chunks
      • Block Types
      • Block Type Registry
      • Chunks
      • Chunk Lattice
    • Camera
    • Chat & Commands
    • Debugging
    • Entities
      • Animations
      • Block Entities
      • Colliders & Hitbox
      • Child Entities
      • Entity Controllers
        • Base Entity Controller
        • Pathfinding Entity Controller
        • DefaultPlayer Entity Controller
        • Simple Entity Controller
      • Entity Manager
      • Model Entities
      • Movement & Pathfinding
      • Player Controlled Entities
    • Events
    • Input & Controls
    • Lighting
      • Ambient Light
      • Light Manager
      • Point Lights
      • Spot Lights
      • Sun Light (Directional)
    • Mobile
    • Persisted Data
    • Players
      • Player Manager
      • Persisted Player Data
    • Plugins
    • Physics
      • Colliders
      • Collision Groups
      • Debugging
      • Gravity
      • Raycasts
      • Rigid Bodies
    • User Interface
      • Overlay UI
      • Scene UIs
      • Scene UI Manager
    • Worlds
      • Map Data Format
  • Helpful Resources
    • HYTOPIA Architecture & Platform Overview
    • Useful Third-Party Tools
Powered by GitBook
On this page
  • Available Inputs
  • Using Player Inputs
  • Mobile Support
  • Cancelling Player Inputs
Export as PDF
  1. SDK Guides

Input & Controls

Making unique game mechanics based on different player inputs can be critical for great games. Because HYTOPIA is architected as a purely server-authoritative game engine, that means all player inputs are streamed to your game, allowing you to directly control the outcome of player inputs each tick!

This is really powerful and allows you to create unique gameplay experiences without replicating input logic between client and server.

Available Inputs

Below is a list of inputs that the HYTOPIA game client will send to your game each tick for each player. You can build custom game logic around any state of these inputs.

These inputs for the relevant player are passed to the onTickWithPlayerInput() method of an Entity Controller every tick. You can also access the current input state of any player though player.inputand player.camera.orientation.

Input
Type
Input State Key(s)
Mobile Support?

W

Boolean (true when pressed, false when not)

w

A

Boolean (true when pressed, false when not)

a

S

Boolean (true when pressed, false when not)

s

D

Boolean (true when pressed, false when not)

d

Mouse Left Click

Boolean (true when pressed, false when not)

ml

Mouse Right Click

Boolean (true when pressed, false when not)

mr

Camera Orientation - Pitch

Number (in radans)

pitch

Camera Orientation - Yaw

Number (in radians)

yaw

Spacebar

Boolean (true when pressed, false when not)

sp

Shift

Boolean (true when pressed, false when not)

sh

Q

Boolean (true when pressed, false when not)

q

E

Boolean (true when pressed, false when not)

e

R

Boolean (true when pressed, false when not)

r

F

Boolean (true when pressed, false when not)

f

Z

Boolean (true when pressed, false when not)

z

X

Boolean (true when pressed, false when not)

x

C

Boolean (true when pressed, false when not)

c

V

Boolean (true when pressed, false when not)

v

Numbers 1-9

Boolean (true when pressed, false when not)

1, 2, 3, 4, 5, 6, 7, 8, 9

Input states are currently stored on the Player class' input (player.input) as abbreviated keys as listed in the table above.

Using Player Inputs

For a great example of how you can use player inputs to specify how a PlayerEntity is controlled, you can check out the DefaultPlayer Entity Controller which shows how it implements the onTickWithPlayerInput()method.

Mobile Support

The HYTOPIA game client implements a set of touch controls on mobile devices like phones and tablets. Because these devices do not have a keyboard and mouse, we are only able to natively support a subset of the full inputs available. See the table in Available Inputs for details.

If you need additional touch inptus for mobile, you can create your own custom user interfaces specifically for mobile devices that overlay additional touch controls. See User Interfaceto learn more.

Cancelling Player Inputs

There may be situations where you need to cancel a current input of a player, even if they haven't stopped pressing it. We can easily do that by setting the input key to false on their player input state as follows.

// other code ...

player.input['sp'] = false; // cancel out the space bar

Another example, let's say you want to only process shooting 1 bullet every time a player clicks, but we don't want to shoot a bullet every tick of the server while the player is holding the mouse down. We can easily accomplish this with the following input state logic.

// other code, likely in the onTickWithPlayerInput() method, or somewhere else ...

if (input.ml) { // the left mouse button is clicked
  // .. fire a bullet
  
  // cancel the input, the player will
  // need to depress and repress the mouse
  // button to fire another bullet, which is
  // the behavior we want.
  input.ml = false;
}
PreviousEventsNextLighting

Last updated 4 months ago

You can see the most up to date list of supported inputs in the .

server protocol repository's InputSchema, here