UNPKG

hytopia

Version:

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

108 lines (51 loc) 2.55 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [server](./server.md) &gt; [Entity](./server.entity.md) &gt; [spawn](./server.entity.spawn.md) ## Entity.spawn() method Spawns the entity in the world. Use for: placing the entity into a world so it simulates and syncs to clients. Do NOT use for: reusing a single entity instance across multiple worlds. **Signature:** ```typescript spawn(world: World, position: Vector3Like, rotation?: QuaternionLike): void; ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td> world </td><td> [World](./server.world.md) </td><td> The world to spawn the entity in. </td></tr> <tr><td> position </td><td> [Vector3Like](./server.vector3like.md) </td><td> The position to spawn the entity at. </td></tr> <tr><td> rotation </td><td> [QuaternionLike](./server.quaternionlike.md) </td><td> _(Optional)_ The optional rotation to spawn the entity with. \*\*Requires:\*\* Entity must not already be spawned. \*\*Side effects:\*\* Registers the entity, adds it to the simulation, and emits `EntityEvent.SPAWN`<!-- -->. \*\*Category:\*\* Entities </td></tr> </tbody></table> **Returns:** void ## Remarks \*\*Rotation default:\*\* If no rotation is provided, entity spawns with identity rotation facing -Z. For Y-axis rotation (yaw): `{ x: 0, y: sin(yaw/2), z: 0, w: cos(yaw/2) }`<!-- -->. Yaw 0 = facing -Z. \*\*Auto-collider creation:\*\* If no colliders are provided, a default collider is auto-generated from the model bounds (or block half extents). Set `modelPreferredShape` to `ColliderShape.NONE` to disable. \*\*Collision groups:\*\* Colliders with default collision groups are auto-assigned based on `isEnvironmental` and `isSensor` flags. Environmental entities don't collide with blocks or other environmental entities. \*\*Event enabling:\*\* Collision/contact force events are auto-enabled on colliders if listeners are registered for `BLOCK_COLLISION`<!-- -->, `ENTITY_COLLISION`<!-- -->, `BLOCK_CONTACT_FORCE`<!-- -->, or `ENTITY_CONTACT_FORCE` prior to spawning. \*\*Controller:\*\* If a controller is attached, `controller.spawn()` is called after the entity is added to the physics simulation. \*\*Parent handling:\*\* If `parent` was set in options, `setParent()` is called after spawn with the provided position/rotation.