UNPKG

hytopia

Version:

The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.

329 lines (152 loc) 5.32 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [server](./server.md) &gt; [SimpleEntityController](./server.simpleentitycontroller.md) ## SimpleEntityController class A simple entity controller with basic movement functions. When to use: straightforward movement and facing without pathfinding. Do NOT use for: obstacle-aware movement; use `PathfindingEntityController`<!-- -->. **Signature:** ```typescript export default class SimpleEntityController extends BaseEntityController ``` **Extends:** [BaseEntityController](./server.baseentitycontroller.md) ## Remarks This class provides straight-line movement and yaw-only facing. It is compatible with kinematic or dynamic rigid bodies. <h2>Coordinate System &amp; Model Orientation</h2> HYTOPIA uses \*\*-Z as forward\*\*. Models must be authored with their front facing -Z. When `face()` rotates an entity to look at a target, it orients the entity's -Z axis toward that target. A yaw of 0 means facing -Z. ## Example ```typescript // Create a custom entity controller for myEntity, prior to spawning it. myEntity.setController(new SimpleEntityController()); // Spawn the entity in the world. myEntity.spawn(world, { x: 53, y: 10, z: 23 }); // Move the entity at a speed of 4 blocks // per second to the coordinate (10, 1, 10). // console.log when we reach the target. myEntity.controller.move({ x: 10, y: 1, z: 10 }, 4, { moveCompleteCallback: endPosition => { console.log('Finished moving to', endPosition); }, }); ``` \*\*Category:\*\* Controllers ## Constructors <table><thead><tr><th> Constructor </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [(constructor)(options)](./server.simpleentitycontroller._constructor_.md) </td><td> </td><td> Constructs a new instance of the `SimpleEntityController` 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> [idleLoopedAnimations](./server.simpleentitycontroller.idleloopedanimations.md) </td><td> </td><td> string\[\] </td><td> The animations to loop when the entity is idle. </td></tr> <tr><td> [idleLoopedAnimationsSpeed](./server.simpleentitycontroller.idleloopedanimationsspeed.md) </td><td> </td><td> number \| undefined </td><td> The speed at which to loop the idle animations. </td></tr> <tr><td> [jumpOneshotAnimations](./server.simpleentitycontroller.jumponeshotanimations.md) </td><td> </td><td> string\[\] </td><td> The animations to play when the entity jumps. </td></tr> <tr><td> [moveLoopedAnimations](./server.simpleentitycontroller.moveloopedanimations.md) </td><td> </td><td> string\[\] </td><td> The animations to loop when the entity is moving. </td></tr> <tr><td> [moveLoopedAnimationsSpeed](./server.simpleentitycontroller.moveloopedanimationsspeed.md) </td><td> </td><td> number \| undefined </td><td> The speed at which to loop the move animations. </td></tr> <tr><td> [moveSpeed](./server.simpleentitycontroller.movespeed.md) </td><td> </td><td> number </td><td> The speed at which to move the entity. Can be altered while moving. </td></tr> </tbody></table> ## Methods <table><thead><tr><th> Method </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [face(target, speed, options)](./server.simpleentitycontroller.face.md) </td><td> </td><td> Rotates the entity at a given speed to face a target coordinate. Use for: turning an entity to look at a target without moving it. Do NOT use for: pitch/roll orientation; this rotates yaw only. </td></tr> <tr><td> [jump(height)](./server.simpleentitycontroller.jump.md) </td><td> </td><td> Applies an upwards impulse to the entity to simulate a jump, only supported for entities with dynamic rigid body types. Use for: a single jump impulse for dynamic entities. Do NOT use for: kinematic entities; this has no effect. </td></tr> <tr><td> [move(target, speed, options)](./server.simpleentitycontroller.move.md) </td><td> </td><td> Moves the entity at a given speed in a straight line to a target coordinate. Use for: simple straight-line movement. Do NOT use for: obstacle avoidance; use `PathfindingEntityController`<!-- -->. </td></tr> <tr><td> [spawn(entity)](./server.simpleentitycontroller.spawn.md) </td><td> </td><td> Override of the `BaseEntityController.spawn` method. Starts the set idle animations (if any) when the entity is spawned. </td></tr> <tr><td> [stopFace()](./server.simpleentitycontroller.stopface.md) </td><td> </td><td> Stops the entity from attempting to face a target coordinate. </td></tr> <tr><td> [stopMove()](./server.simpleentitycontroller.stopmove.md) </td><td> </td><td> Stops the entity from continuing to move to its current target coordinate. </td></tr> </tbody></table>