Player Controlled Entities
Last updated
Last updated
Player controlled entities, represented by the , are entities that are controlled by a player's inputs. Player controlled entities can be either a Model Entitiesor a Block Entities. Yes, that means if you really want, you could even have players control a movable block in your game!
If you only need the default player character that can move around, and supports all standard behaviors for HYTOPIA, you'll use an instance of the DefaultPlayerEntity class.
The PlayerEntity class is primarily meant for situations where you need to have full control over player behaviors for inputs, their representative model, etc. PlayerEntity is a lower level implementation that gives more control compared to DefaultPlayerEntity.
The behavior of the PlayerEntity class based on player inputs is dependent on the logic in it's entity controller (playerEntity.controller
).
In our Entity Controllers section, we covered the lifecycle of an entity controller. Entity controllers have a special lifecycle method called tickWithPlayerInput()
. A PlayerEntity invokes this method of it's controller every tick, passing the current inputs of the player to it.
Through this, the PlayerEntity class, which represents a player controlled entity, is controlled through the logic of it's entity controller based on the input of the player each tick.
To learn more about player inputs and controls, check out Input & Controls
Here's an example from our boilerplate, showcasing how we create a new player entity controlled by a player when they join our game.
You can .