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.input
and player.camera.orientation
.
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
You can see the most up to date list of supported inputs in the server protocol repository's InputSchema, here.
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 Player 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.
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.
Last updated