hytopia
Version:
The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.
748 lines (327 loc) • 11 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [server](./server.md) > [DefaultPlayerEntityController](./server.defaultplayerentitycontroller.md)
## DefaultPlayerEntityController class
The default player entity controller implementation.
When to use: player-controlled avatars using `DefaultPlayerEntity`<!-- -->. Do NOT use for: NPCs or non-player entities; use `SimpleEntityController` or `PathfindingEntityController` instead.
**Signature:**
```typescript
export default class DefaultPlayerEntityController extends BaseEntityController
```
**Extends:** [BaseEntityController](./server.baseentitycontroller.md)
## Remarks
Extends `BaseEntityController` and implements default movement, platforming, jumping, and swimming. You can extend this class to add custom logic.
<h2>Coordinate System & Model Orientation</h2>
HYTOPIA uses \*\*-Z as forward\*\*. Models must be authored with their front facing -Z. A yaw of 0 means facing -Z. The controller rotates the entity based on camera yaw and movement direction, always orienting the entity's -Z axis in the intended facing direction.
## Example
```typescript
// Create a custom entity controller for myEntity, prior to spawning it.
myEntity.setController(new DefaultPlayerEntityController({
jumpVelocity: 10,
runVelocity: 8,
walkVelocity: 4,
}));
// Spawn the entity in the world.
myEntity.spawn(world, { x: 53, y: 10, z: 23 });
```
\*\*Category:\*\* Controllers
## Constructors
<table><thead><tr><th>
Constructor
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[(constructor)(options)](./server.defaultplayerentitycontroller._constructor_.md)
</td><td>
</td><td>
Constructs a new instance of the `DefaultPlayerEntityController` class
</td></tr>
</tbody></table>
## Properties
<table><thead><tr><th>
Property
</th><th>
Modifiers
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[applyDirectionalMovementRotations](./server.defaultplayerentitycontroller.applydirectionalmovementrotations.md)
</td><td>
</td><td>
boolean
</td><td>
Whether to apply directional rotations to the entity while moving, defaults to true.
</td></tr>
<tr><td>
[autoCancelMouseLeftClick](./server.defaultplayerentitycontroller.autocancelmouseleftclick.md)
</td><td>
</td><td>
boolean
</td><td>
Whether to automatically cancel left click input after first processed tick, defaults to true.
</td></tr>
<tr><td>
[canJump](./server.defaultplayerentitycontroller.canjump.md)
</td><td>
</td><td>
(controller: [DefaultPlayerEntityController](./server.defaultplayerentitycontroller.md)<!-- -->) => boolean
</td><td>
A function allowing custom logic to determine if the entity can jump.
</td></tr>
<tr><td>
[canRun](./server.defaultplayerentitycontroller.canrun.md)
</td><td>
</td><td>
(controller: [DefaultPlayerEntityController](./server.defaultplayerentitycontroller.md)<!-- -->) => boolean
</td><td>
A function allowing custom logic to determine if the entity can run.
</td></tr>
<tr><td>
[canSwim](./server.defaultplayerentitycontroller.canswim.md)
</td><td>
</td><td>
(controller: [DefaultPlayerEntityController](./server.defaultplayerentitycontroller.md)<!-- -->) => boolean
</td><td>
A function allowing custom logic to determine if the entity can swim.
</td></tr>
<tr><td>
[canWalk](./server.defaultplayerentitycontroller.canwalk.md)
</td><td>
</td><td>
(controller: [DefaultPlayerEntityController](./server.defaultplayerentitycontroller.md)<!-- -->) => boolean
</td><td>
A function allowing custom logic to determine if the entity can walk.
</td></tr>
<tr><td>
[facesCameraWhenIdle](./server.defaultplayerentitycontroller.facescamerawhenidle.md)
</td><td>
</td><td>
boolean
</td><td>
Whether the entity rotates to face the camera direction when idle. When `true`<!-- -->, the entity always faces the camera direction. When `false`<!-- -->, the entity only rotates while actively moving.
</td></tr>
<tr><td>
[idleLoopedAnimations](./server.defaultplayerentitycontroller.idleloopedanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The looped animation(s) that will play when the entity is idle.
</td></tr>
<tr><td>
[interactOneshotAnimations](./server.defaultplayerentitycontroller.interactoneshotanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The oneshot animation(s) that will play when the entity interacts (left click)
</td></tr>
<tr><td>
[isActivelyMoving](./server.defaultplayerentitycontroller.isactivelymoving.md)
</td><td>
`readonly`
</td><td>
boolean
</td><td>
Whether the entity is moving from player inputs.
\*\*Category:\*\* Controllers
</td></tr>
<tr><td>
[isGrounded](./server.defaultplayerentitycontroller.isgrounded.md)
</td><td>
`readonly`
</td><td>
boolean
</td><td>
Whether the entity is grounded.
\*\*Category:\*\* Controllers
</td></tr>
<tr><td>
[isOnPlatform](./server.defaultplayerentitycontroller.isonplatform.md)
</td><td>
`readonly`
</td><td>
boolean
</td><td>
Whether the entity is on a platform.
</td></tr>
<tr><td>
[isSwimming](./server.defaultplayerentitycontroller.isswimming.md)
</td><td>
`readonly`
</td><td>
boolean
</td><td>
Whether the entity is swimming.
</td></tr>
<tr><td>
[jumpLandHeavyOneshotAnimations](./server.defaultplayerentitycontroller.jumplandheavyoneshotanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The oneshot animation(s) that will play when the entity lands with a high velocity.
</td></tr>
<tr><td>
[jumpLandLightOneshotAnimations](./server.defaultplayerentitycontroller.jumplandlightoneshotanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The oneshot animation(s) that will play when the entity lands after jumping or being airborne.
</td></tr>
<tr><td>
[jumpOneshotAnimations](./server.defaultplayerentitycontroller.jumponeshotanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The oneshot animation(s) that will play when the entity is jumping.
</td></tr>
<tr><td>
[jumpVelocity](./server.defaultplayerentitycontroller.jumpvelocity.md)
</td><td>
</td><td>
number
</td><td>
The upward velocity applied to the entity when it jumps.
</td></tr>
<tr><td>
[platform](./server.defaultplayerentitycontroller.platform.md)
</td><td>
`readonly`
</td><td>
[Entity](./server.entity.md) \| undefined
</td><td>
The platform the entity is on, if any.
\*\*Category:\*\* Controllers
</td></tr>
<tr><td>
[runLoopedAnimations](./server.defaultplayerentitycontroller.runloopedanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The looped animation(s) that will play when the entity is running.
</td></tr>
<tr><td>
[runVelocity](./server.defaultplayerentitycontroller.runvelocity.md)
</td><td>
</td><td>
number
</td><td>
The normalized horizontal velocity applied to the entity when it runs.
</td></tr>
<tr><td>
[sticksToPlatforms](./server.defaultplayerentitycontroller.stickstoplatforms.md)
</td><td>
</td><td>
boolean
</td><td>
Whether the entity sticks to platforms.
</td></tr>
<tr><td>
[swimFastVelocity](./server.defaultplayerentitycontroller.swimfastvelocity.md)
</td><td>
</td><td>
number
</td><td>
The normalized horizontal velocity applied to the entity when it swims fast (equivalent to running).
</td></tr>
<tr><td>
[swimGravity](./server.defaultplayerentitycontroller.swimgravity.md)
</td><td>
</td><td>
number
</td><td>
The gravity modifier applied to the entity when swimming.
</td></tr>
<tr><td>
[swimIdleLoopedAnimations](./server.defaultplayerentitycontroller.swimidleloopedanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The looped animation(s) that will play when the entity is not moving while swimming.
</td></tr>
<tr><td>
[swimLoopedAnimations](./server.defaultplayerentitycontroller.swimloopedanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The looped animation(s) that will play when the entity is swimming in any direction.
</td></tr>
<tr><td>
[swimMaxGravityVelocity](./server.defaultplayerentitycontroller.swimmaxgravityvelocity.md)
</td><td>
</td><td>
number
</td><td>
The maximum downward velocity that the entity can reach when affected by gravity while swimming.
</td></tr>
<tr><td>
[swimSlowVelocity](./server.defaultplayerentitycontroller.swimslowvelocity.md)
</td><td>
</td><td>
number
</td><td>
The normalized horizontal velocity applied to the entity when it swims slowly (equivalent to walking).
</td></tr>
<tr><td>
[swimUpwardVelocity](./server.defaultplayerentitycontroller.swimupwardvelocity.md)
</td><td>
</td><td>
number
</td><td>
The upward velocity applied to the entity when swimming.
</td></tr>
<tr><td>
[walkLoopedAnimations](./server.defaultplayerentitycontroller.walkloopedanimations.md)
</td><td>
</td><td>
string\[\]
</td><td>
The looped animation(s) that will play when the entity is walking.
</td></tr>
<tr><td>
[walkVelocity](./server.defaultplayerentitycontroller.walkvelocity.md)
</td><td>
</td><td>
number
</td><td>
The normalized horizontal velocity applied to the entity when it walks.
</td></tr>
</tbody></table>
## Methods
<table><thead><tr><th>
Method
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[attach(entity)](./server.defaultplayerentitycontroller.attach.md)
</td><td>
</td><td>
Called when the controller is attached to an entity.
</td></tr>
<tr><td>
[spawn(entity)](./server.defaultplayerentitycontroller.spawn.md)
</td><td>
</td><td>
Called when the controlled entity is spawned. In DefaultPlayerEntityController, this function is used to create the colliders for the entity for wall and ground detection.
</td></tr>
<tr><td>
[tickWithPlayerInput(entity, input, cameraOrientation, deltaTimeMs)](./server.defaultplayerentitycontroller.tickwithplayerinput.md)
</td><td>
</td><td>
Ticks the player movement for the entity controller, overriding the default implementation. If the entity to tick is a child entity, only the event will be emitted but the default movement logic will not be applied.
</td></tr>
</tbody></table>