UNPKG

hytopia

Version:

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

316 lines (145 loc) 4.74 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. **Signature:** ```typescript export default class SimpleEntityController extends BaseEntityController ``` **Extends:** [BaseEntityController](./server.baseentitycontroller.md) ## Remarks This class implements simple movement methods that serve as a way to add realistic movement and rotational facing functionality to an entity. This is also a great base to extend for your own more complex entity controller that implements things like pathfinding. Compatible with entities that have kinematic or dynamic rigid body types. ## 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); }, }); ``` ## 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. </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. </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. </td></tr> <tr><td> [spawn(entity)](./server.simpleentitycontroller.spawn.md) </td><td> </td><td> Override of the [BaseEntityController.spawn()](./server.baseentitycontroller.spawn.md) 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 it's current target coordinate. </td></tr> </tbody></table>