hytopia 0.1.49 → 0.1.51

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.
Files changed (45) hide show
  1. package/boilerplate/assets/map.json +2623 -0
  2. package/docs/server.basecharactercontroller.md +4 -4
  3. package/docs/server.basecharactercontroller.ontickwithplayerinput.md +13 -0
  4. package/docs/{server.basecharactercontroller.tickplayermovement.md → server.basecharactercontroller.tickwithplayerinput.md} +8 -8
  5. package/docs/server.defaultcharactercontroller.md +1 -1
  6. package/docs/{server.defaultcharactercontroller.tickplayermovement.md → server.defaultcharactercontroller.tickwithplayerinput.md} +8 -8
  7. package/docs/server.md +5 -5
  8. package/docs/server.player.cameraorientation.md +13 -0
  9. package/docs/server.player.input.md +13 -0
  10. package/docs/server.player.md +9 -9
  11. package/docs/server.playercameraorientation.md +16 -0
  12. package/docs/server.playerinput.md +13 -0
  13. package/docs/server.simulation.enabledebugraycasting.md +53 -0
  14. package/docs/server.simulation.enabledebugrendering.md +1 -1
  15. package/docs/server.simulation.isdebugraycastingenabled.md +13 -0
  16. package/docs/server.simulation.md +36 -1
  17. package/docs/server.supported_input_keys.md +1 -1
  18. package/examples/big-world/README.md +4 -0
  19. package/examples/big-world/package.json +14 -0
  20. package/examples/block-entity/README.md +3 -0
  21. package/examples/block-entity/assets/map.json +2623 -0
  22. package/examples/block-entity/package.json +15 -0
  23. package/examples/character-controller/MyCharacterController.ts +8 -8
  24. package/examples/character-controller/README.md +4 -0
  25. package/examples/character-controller/assets/map.json +2623 -0
  26. package/examples/character-controller/package.json +15 -0
  27. package/examples/custom-ui/README.md +4 -0
  28. package/examples/custom-ui/assets/map.json +2623 -0
  29. package/examples/custom-ui/package.json +15 -0
  30. package/examples/entity-spawn/README.md +3 -0
  31. package/examples/entity-spawn/assets/map.json +2623 -0
  32. package/examples/entity-spawn/package.json +15 -0
  33. package/examples/payload-game/README.md +8 -0
  34. package/examples/payload-game/assets/ui/index.html +42 -0
  35. package/examples/payload-game/index.ts +24 -18
  36. package/examples/payload-game/package.json +15 -0
  37. package/package.json +1 -1
  38. package/server.api.json +191 -113
  39. package/server.d.ts +34 -23
  40. package/server.js +80 -80
  41. package/docs/server.basecharactercontroller.ontickplayermovement.md +0 -13
  42. package/docs/server.player.inputstate.md +0 -13
  43. package/docs/server.player.orientationstate.md +0 -13
  44. package/docs/server.playerinputstate.md +0 -13
  45. package/docs/server.playerorientationstate.md +0 -16
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "entity-spawn",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "devDependencies": {
13
+ "@hytopia.com/assets": "^0.1.6"
14
+ }
15
+ }
@@ -0,0 +1,8 @@
1
+ # payload-game
2
+
3
+ A simple implementation of a PvE style push the payload game.
4
+
5
+ In this game, the player can type `/start` to start. Spiders will begin spawning and the player must
6
+ click to shoot to kill the spiders while staying near the payload to keep it moving.
7
+
8
+ Spiders continually spawn and increase in spawn rate as the player gets closers to the destination.
@@ -0,0 +1,42 @@
1
+ <html></html>
2
+ <body>
3
+ <!--
4
+ The Hytopia-ui script MUST be included, otherwise your
5
+ UI won't function correctly and your game scene will not
6
+ be interactable when using custom UI.
7
+ -->
8
+ <script src="https://unpkg.com/hytopia-ui@latest/dist/index.umd.js"></script>
9
+
10
+ <style>
11
+ .crosshair {
12
+ position: fixed;
13
+ top: 50%;
14
+ left: 50%;
15
+ transform: translate(-50%, -50%);
16
+ width: 20px;
17
+ height: 20px;
18
+ opacity: 0.5;
19
+ pointer-events: none;
20
+ }
21
+ .crosshair::before,
22
+ .crosshair::after {
23
+ content: '';
24
+ position: absolute;
25
+ background-color: white;
26
+ }
27
+ .crosshair::before {
28
+ width: 2px;
29
+ height: 100%;
30
+ left: 50%;
31
+ transform: translateX(-50%);
32
+ }
33
+ .crosshair::after {
34
+ height: 2px;
35
+ width: 100%;
36
+ top: 50%;
37
+ transform: translateY(-50%);
38
+ }
39
+ </style>
40
+ <div class="crosshair"></div>
41
+ </body>
42
+ </html>
@@ -27,13 +27,14 @@ import {
27
27
  PlayerEntity,
28
28
  RigidBodyType,
29
29
  SimpleCharacterController,
30
+ Vector3,
30
31
  World,
31
32
  startServer,
32
33
  } from 'hytopia';
33
34
 
34
35
  import type {
35
- PlayerInputState,
36
- PlayerOrientationState,
36
+ PlayerInput,
37
+ PlayerCameraOrientation,
37
38
  QuaternionLike,
38
39
  Vector3Like,
39
40
  } from 'hytopia';
@@ -106,6 +107,8 @@ startServer(world => { // Perform our game setup logic in the startServer init c
106
107
  modelScale: 0.5,
107
108
  });
108
109
 
110
+ player.ui.load('ui/index.html');
111
+
109
112
  // Setup a first person camera for the player
110
113
  player.camera.setMode(PlayerCameraMode.FIRST_PERSON); // set first person mode
111
114
  player.camera.setOffset({ x: 0, y: 0.4, z: 0 }); // shift camrea up on Y axis so we see from "head" perspective.
@@ -117,7 +120,7 @@ startServer(world => { // Perform our game setup logic in the startServer init c
117
120
  playerEntity.spawn(world, randomSpawnCoordinate);
118
121
 
119
122
  // We need to do some custom logic for player inputs, so let's assign custom onTick handler to the default player controller.
120
- playerEntity.characterController!.onTickPlayerMovement = onTickPlayerMovement;
123
+ playerEntity.characterController!.onTickWithPlayerInput = onTickWithPlayerInput;
121
124
 
122
125
  // Set custom collision groups for the player entity, this is so we can reference the PLAYER collision group
123
126
  // specifically in enemy collision sensors.
@@ -492,17 +495,31 @@ function onTickPathfindEnemy(entity: Entity, targetPlayers: Set<PlayerEntity>, s
492
495
  enemyPathfindAccumulators[entityId]++;
493
496
  }
494
497
 
495
- function onTickPlayerMovement(this: DefaultCharacterController, inputState: PlayerInputState, orientationState: PlayerOrientationState, _deltaTimeMs: number) {
498
+ function onTickWithPlayerInput(this: DefaultCharacterController, input: PlayerInput, cameraOrientation: PlayerCameraOrientation, _deltaTimeMs: number) {
496
499
  if (!this.entity.world) return;
497
500
 
498
- if (inputState.ml) {
501
+ if (input.ml) {
499
502
  const world = this.entity.world;
500
503
  const entity = this.entity;
501
- const direction = getDirectionFromOrientation(orientationState);
504
+ const direction = Vector3.fromVector3Like(entity.getDirectionFromRotation());
505
+
506
+ direction.y = Math.sin(cameraOrientation.pitch);
507
+
508
+ // Adjust horizontal components based on pitch
509
+ const cosP = Math.cos(cameraOrientation.pitch);
510
+ direction.x = -direction.x * cosP;
511
+ direction.z = -direction.z * cosP;
512
+
513
+ // Normalize the direction vector to unit length
514
+ direction.normalize();
502
515
 
503
516
  this.entity.startModelOneshotAnimations([ 'shoot' ]);
504
517
 
505
- const bullet = spawnBullet(world, entity.getTranslation(), direction);
518
+ // Adjust bullet origin roughly for camera offset so crosshair is accurate
519
+ const bulletOrigin = entity.getTranslation();
520
+ bulletOrigin.y += 0.65;
521
+
522
+ const bullet = spawnBullet(world, bulletOrigin, direction);
506
523
  setTimeout(() => bullet.isSpawned && bullet.despawn(), 2000);
507
524
  }
508
525
  }
@@ -529,17 +546,6 @@ function damagePlayer(playerEntity: PlayerEntity) {
529
546
  }
530
547
  }
531
548
 
532
- function getDirectionFromOrientation(orientationState: PlayerOrientationState): Vector3Like {
533
- const { yaw, pitch } = orientationState;
534
- const cosPitch = Math.cos(pitch);
535
-
536
- return {
537
- x: -Math.sin(yaw) * cosPitch,
538
- y: Math.sin(pitch),
539
- z: -Math.cos(yaw) * cosPitch,
540
- };
541
- }
542
-
543
549
  function getRotationFromDirection(direction: Vector3Like): QuaternionLike {
544
550
  // Calculate yaw (rotation around Y-axis)
545
551
  const yaw = Math.atan2(-direction.x, -direction.z);
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "payload-game",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "devDependencies": {
13
+ "@hytopia.com/assets": "^0.1.6"
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hytopia",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
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": {