hytopia 0.1.64 → 0.1.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -449,6 +449,38 @@ Enables or disables collision events for the collider. This is automatically ena
449
449
  Enables or disables contact force events for the collider. This is automatically enabled if an on contact force callback is set.
450
450
 
451
451
 
452
+ </td></tr>
453
+ <tr><td>
454
+
455
+ [optionsFromBlockHalfExtents(halfExtents)](./server.collider.optionsfromblockhalfextents.md)
456
+
457
+
458
+ </td><td>
459
+
460
+ `static`
461
+
462
+
463
+ </td><td>
464
+
465
+ Creates a collider options object from a block's half extents.
466
+
467
+
468
+ </td></tr>
469
+ <tr><td>
470
+
471
+ [optionsFromModelUri(modelUri, scale)](./server.collider.optionsfrommodeluri.md)
472
+
473
+
474
+ </td><td>
475
+
476
+ `static`
477
+
478
+
479
+ </td><td>
480
+
481
+ Creates a collider options object from a modelUri with best approximate shape and size.
482
+
483
+
452
484
  </td></tr>
453
485
  <tr><td>
454
486
 
@@ -0,0 +1,55 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [Collider](./server.collider.md) &gt; [optionsFromBlockHalfExtents](./server.collider.optionsfromblockhalfextents.md)
4
+
5
+ ## Collider.optionsFromBlockHalfExtents() method
6
+
7
+ Creates a collider options object from a block's half extents.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ static optionsFromBlockHalfExtents(halfExtents: Vector3Like): ColliderOptions;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ halfExtents
36
+
37
+
38
+ </td><td>
39
+
40
+ [Vector3Like](./server.vector3like.md)
41
+
42
+
43
+ </td><td>
44
+
45
+ The half extents of the block.
46
+
47
+
48
+ </td></tr>
49
+ </tbody></table>
50
+ **Returns:**
51
+
52
+ [ColliderOptions](./server.collideroptions.md)
53
+
54
+ The collider options object.
55
+
@@ -0,0 +1,71 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [Collider](./server.collider.md) &gt; [optionsFromModelUri](./server.collider.optionsfrommodeluri.md)
4
+
5
+ ## Collider.optionsFromModelUri() method
6
+
7
+ Creates a collider options object from a modelUri with best approximate shape and size.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ static optionsFromModelUri(modelUri: string, scale?: number): ColliderOptions;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ modelUri
36
+
37
+
38
+ </td><td>
39
+
40
+ string
41
+
42
+
43
+ </td><td>
44
+
45
+ The URI of the model.
46
+
47
+
48
+ </td></tr>
49
+ <tr><td>
50
+
51
+ scale
52
+
53
+
54
+ </td><td>
55
+
56
+ number
57
+
58
+
59
+ </td><td>
60
+
61
+ _(Optional)_
62
+
63
+
64
+ </td></tr>
65
+ </tbody></table>
66
+ **Returns:**
67
+
68
+ [ColliderOptions](./server.collideroptions.md)
69
+
70
+ The collider options object.
71
+
@@ -63,6 +63,27 @@ Description
63
63
  The singleton instance of the game server.
64
64
 
65
65
 
66
+ </td></tr>
67
+ <tr><td>
68
+
69
+ [modelManager](./server.gameserver.modelmanager.md)
70
+
71
+
72
+ </td><td>
73
+
74
+ `readonly`
75
+
76
+
77
+ </td><td>
78
+
79
+ [ModelManager](./server.modelmanager.md)
80
+
81
+
82
+ </td><td>
83
+
84
+ The model manager for the game server.
85
+
86
+
66
87
  </td></tr>
67
88
  <tr><td>
68
89
 
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [GameServer](./server.gameserver.md) &gt; [modelManager](./server.gameserver.modelmanager.md)
4
+
5
+ ## GameServer.modelManager property
6
+
7
+ The model manager for the game server.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ get modelManager(): ModelManager;
13
+ ```
package/docs/server.md CHANGED
@@ -170,6 +170,17 @@ Manages event emission and assigned listener callbacks.
170
170
  Manages the game and associated worlds and systems.
171
171
 
172
172
 
173
+ </td></tr>
174
+ <tr><td>
175
+
176
+ [ModelManager](./server.modelmanager.md)
177
+
178
+
179
+ </td><td>
180
+
181
+ Manages model data for all known models of the game.
182
+
183
+
173
184
  </td></tr>
174
185
  <tr><td>
175
186
 
@@ -901,17 +912,6 @@ Description
901
912
  </th></tr></thead>
902
913
  <tbody><tr><td>
903
914
 
904
- [DEFAULT\_BLOCK\_ENTITY\_RIGID\_BODY\_OPTIONS](./server.default_block_entity_rigid_body_options.md)
905
-
906
-
907
- </td><td>
908
-
909
- The default rigid body options for a block entity when EntityOptions.rigidBodyOptions is not provided.
910
-
911
-
912
- </td></tr>
913
- <tr><td>
914
-
915
915
  [DEFAULT\_ENTITY\_RIGID\_BODY\_OPTIONS](./server.default_entity_rigid_body_options.md)
916
916
 
917
917
 
@@ -0,0 +1,55 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelManager](./server.modelmanager.md) &gt; [getBoundingBox](./server.modelmanager.getboundingbox.md)
4
+
5
+ ## ModelManager.getBoundingBox() method
6
+
7
+ Retrieves the bounding box of a model.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ getBoundingBox(modelUri: string): ModelBoundingBox;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ modelUri
36
+
37
+
38
+ </td><td>
39
+
40
+ string
41
+
42
+
43
+ </td><td>
44
+
45
+ The URI of the model to retrieve the bounding box for.
46
+
47
+
48
+ </td></tr>
49
+ </tbody></table>
50
+ **Returns:**
51
+
52
+ ModelBoundingBox
53
+
54
+ The bounding box of the model.
55
+
@@ -0,0 +1,13 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelManager](./server.modelmanager.md) &gt; [instance](./server.modelmanager.instance.md)
4
+
5
+ ## ModelManager.instance property
6
+
7
+ The global PlayerManager instance as a singleton.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ static readonly instance: ModelManager;
13
+ ```
@@ -0,0 +1,111 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [server](./server.md) &gt; [ModelManager](./server.modelmanager.md)
4
+
5
+ ## ModelManager class
6
+
7
+ Manages model data for all known models of the game.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ export default class ModelManager
13
+ ```
14
+
15
+ ## Remarks
16
+
17
+ The ModelManager is created internally as a global singletone accessible with the static property `ModelManager.instance`<!-- -->.
18
+
19
+ The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `ModelManager` class.
20
+
21
+ ## Example
22
+
23
+
24
+ ```typescript
25
+ import { ModelManager } from 'hytopia';
26
+
27
+ const modelManager = ModelManager.instance;
28
+ const boundingBox = modelManager.getBoundingBox('models/player.gltf');
29
+ ```
30
+
31
+ ## Properties
32
+
33
+ <table><thead><tr><th>
34
+
35
+ Property
36
+
37
+
38
+ </th><th>
39
+
40
+ Modifiers
41
+
42
+
43
+ </th><th>
44
+
45
+ Type
46
+
47
+
48
+ </th><th>
49
+
50
+ Description
51
+
52
+
53
+ </th></tr></thead>
54
+ <tbody><tr><td>
55
+
56
+ [instance](./server.modelmanager.instance.md)
57
+
58
+
59
+ </td><td>
60
+
61
+ `static`
62
+
63
+ `readonly`
64
+
65
+
66
+ </td><td>
67
+
68
+ [ModelManager](./server.modelmanager.md)
69
+
70
+
71
+ </td><td>
72
+
73
+ The global PlayerManager instance as a singleton.
74
+
75
+
76
+ </td></tr>
77
+ </tbody></table>
78
+
79
+ ## Methods
80
+
81
+ <table><thead><tr><th>
82
+
83
+ Method
84
+
85
+
86
+ </th><th>
87
+
88
+ Modifiers
89
+
90
+
91
+ </th><th>
92
+
93
+ Description
94
+
95
+
96
+ </th></tr></thead>
97
+ <tbody><tr><td>
98
+
99
+ [getBoundingBox(modelUri)](./server.modelmanager.getboundingbox.md)
100
+
101
+
102
+ </td><td>
103
+
104
+
105
+ </td><td>
106
+
107
+ Retrieves the bounding box of a model.
108
+
109
+
110
+ </td></tr>
111
+ </tbody></table>
@@ -398,7 +398,7 @@ _(Optional)_ The soft continuous collision detection prediction of the rigid bod
398
398
  </td></tr>
399
399
  <tr><td>
400
400
 
401
- [type](./server.rigidbodyoptions.type.md)
401
+ [type?](./server.rigidbodyoptions.type.md)
402
402
 
403
403
 
404
404
  </td><td>
@@ -411,7 +411,7 @@ _(Optional)_ The soft continuous collision detection prediction of the rigid bod
411
411
 
412
412
  </td><td>
413
413
 
414
- The type of the rigid body.
414
+ _(Optional)_ The type of the rigid body.
415
415
 
416
416
 
417
417
  </td></tr>
@@ -9,5 +9,5 @@ The type of the rigid body.
9
9
  **Signature:**
10
10
 
11
11
  ```typescript
12
- type: RigidBodyType;
12
+ type?: RigidBodyType;
13
13
  ```
@@ -5,6 +5,7 @@ import {
5
5
  PlayerEntity,
6
6
  RigidBodyType,
7
7
  World,
8
+ Collider,
8
9
  } from 'hytopia';
9
10
 
10
11
  import worldMap from './assets/map.json';
@@ -30,16 +31,8 @@ startServer(world => {
30
31
  // set any colliders, the entity will not be affected by physics.
31
32
  // Learn more about collider options here: https://github.com/hytopiagg/sdk/blob/main/docs/server.collideroptions.md
32
33
  colliders: [
33
- {
34
- shape: ColliderShape.ROUND_CYLINDER,
35
- // We manually set the collider sizings to match the model,
36
- // this gives the most control. There is currently no way
37
- // to automatically size colliders to a model.
38
- radius: 3,
39
- halfHeight: 1.7,
40
- borderRadius: 0.2,
41
- tag: 'hitbox', // Tags can be useful for our own logic, they serve no other purpose.
42
- },
34
+ // Get hitbox collider as collider options based on the model & scale.
35
+ Collider.optionsFromModelUri('models/spider.gltf', 3),
43
36
  {
44
37
  shape: ColliderShape.CYLINDER,
45
38
  halfHeight: 1.7,
@@ -30,6 +30,7 @@ import {
30
30
  Vector3,
31
31
  World,
32
32
  startServer,
33
+ Collider,
33
34
  } from 'hytopia';
34
35
 
35
36
  import type {
@@ -224,17 +225,6 @@ function spawnBullet(world: World, coordinate: Vector3Like, direction: Vector3Li
224
225
  z: direction.z * BULLET_SPEED,
225
226
  },
226
227
  rotation: getRotationFromDirection(direction), // Get the rotation from the direction vector so it's facing the right way we shot it
227
- colliders: [
228
- {
229
- shape: ColliderShape.BALL,
230
- radius: 0.1,
231
- isSensor: true,
232
- collisionGroups: {
233
- belongsTo: [ CollisionGroup.ENTITY_SENSOR ],
234
- collidesWith: [ CollisionGroup.ENTITY, CollisionGroup.BLOCK ],
235
- },
236
- },
237
- ],
238
228
  },
239
229
  });
240
230
 
@@ -301,14 +291,8 @@ function spawnPayloadEntity(world: World) {
301
291
  rigidBodyOptions: {
302
292
  type: RigidBodyType.KINEMATIC_POSITION,
303
293
  colliders: [
304
- {
305
- shape: ColliderShape.BLOCK,
306
- halfExtents: { x: 0.9, y: 1.6, z: 2.5 }, // Note: We manually set the collider size, the SDK currently does not support automatic sizing of colliders to a model.
307
- collisionGroups: {
308
- belongsTo: [ CollisionGroup.ALL ],
309
- collidesWith: [ CollisionGroup.ENTITY, CollisionGroup.ENTITY_SENSOR, CollisionGroup.PLAYER ],
310
- },
311
- },
294
+ // Get hitbox collider as collider options based on the model & scale.
295
+ Collider.optionsFromModelUri('models/payload.gltf', 0.7),
312
296
  {
313
297
  shape: ColliderShape.BLOCK, // Create a proximity sensor for movement when players are near.
314
298
  halfExtents: { x: 3.75, y: 2, z: 6 },
@@ -359,17 +343,8 @@ function spawnSpider(world: World, coordinate: Vector3Like) {
359
343
  type: RigidBodyType.DYNAMIC,
360
344
  enabledRotations: { x: false, y: true, z: false },
361
345
  colliders: [
362
- {
363
- shape: ColliderShape.ROUND_CYLINDER,
364
- borderRadius: 0.1 * randomScaleMultiplier,
365
- halfHeight: 0.225 * randomScaleMultiplier,
366
- radius: 0.5 * randomScaleMultiplier,
367
- tag: 'body', // Note we use tags here, they don't really serve a purpose in this example other than showing that they can be used.
368
- collisionGroups: {
369
- belongsTo: [ CollisionGroup.ENTITY ],
370
- collidesWith: [ CollisionGroup.BLOCK, CollisionGroup.ENTITY_SENSOR, CollisionGroup.PLAYER ],
371
- },
372
- },
346
+ // Get hitbox collider as collider options based on the model & scale.
347
+ Collider.optionsFromModelUri('models/spider.gltf', baseScale * randomScaleMultiplier),
373
348
  {
374
349
  shape: ColliderShape.CYLINDER,
375
350
  radius: 20,
@@ -8,10 +8,10 @@ import {
8
8
  startServer,
9
9
  Player,
10
10
  PlayerEntity,
11
- PlayerEntityController,
12
11
  RigidBodyType,
13
12
  SimpleEntityController,
14
13
  World,
14
+ Collider,
15
15
  } from 'hytopia';
16
16
 
17
17
  import worldMap from './assets/map.json';
@@ -75,12 +75,7 @@ function setupJoinNPC(world: World) {
75
75
  type: RigidBodyType.FIXED, // It won't ever move, so we can use a fixed body
76
76
  rotation: { x: 0, y: 1, z: 0, w: 0 }, // Rotate the NPC to face the player
77
77
  colliders: [
78
- { // Hitbox/body collider
79
- shape: ColliderShape.CYLINDER,
80
- radius: 0.3,
81
- halfHeight: 1.2,
82
- tag: 'body',
83
- },
78
+ Collider.optionsFromModelUri('models/mindflayer.gltf', 0.5), // Uses the model's bounding box to create the hitbox collider
84
79
  { // Create a sensor that teleports the player into the game
85
80
  shape: ColliderShape.BLOCK,
86
81
  halfExtents: { x: 1.5, y: 1, z: 1.5 }, // size it slightly smaller than the platform the join NPC is standing on
@@ -267,8 +262,8 @@ function onPlayerJoin(world: World, player: Player) {
267
262
  });
268
263
 
269
264
  playerEntity.onTick = () => {
270
- if (playerEntity.position.y < -3) {
271
- // Assume the player has fallen off the map in the game
265
+ if (playerEntity.position.y < -3 || playerEntity.position.y > 10) {
266
+ // Assume the player has fallen off the map or shot over the wall
272
267
  endGame(playerEntity);
273
268
  }
274
269
  };
@@ -314,7 +309,7 @@ function getRandomSpawnCoordinate() {
314
309
 
315
310
  function updateTopScores() {
316
311
  const topScores = Array.from(PLAYER_TOP_SCORES.entries())
317
- .sort((a, b) => a[1] - b[1])
312
+ .sort((a, b) => b[1] - a[1])
318
313
  .map(([ player, score ]) => ({ player, score }));
319
314
 
320
315
  // Get the top 10 highest scores
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hytopia",
3
- "version": "0.1.64",
3
+ "version": "0.1.65",
4
4
  "description": "The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.",
5
5
  "main": "server.js",
6
6
  "bin": {