diff --git a/content/creator/sdk7/interactivity/player-avatar.md b/content/creator/sdk7/interactivity/player-avatar.md index 1270f0af..b948da5d 100644 --- a/content/creator/sdk7/interactivity/player-avatar.md +++ b/content/creator/sdk7/interactivity/player-avatar.md @@ -263,6 +263,61 @@ InputModifier.createOrReplace(engine.PlayerEntity, { }) ``` +## Locomotion Settings + +You can affect the player's locomotion, like their running speed, jump height, and more. This can be altered dynamically, for example to allow a player to collect a temporary speed boost by interacting with a item, or to disable the player's ability to jump for a short period of time. + +To do this, add an `AvatarLocomotionSettings` component to the `engine.PlayerEntity`. + +```ts +import {AvatarLocomotionSettings, engine} from '@dcl/sdk/ecs' + +AvatarLocomotionSettings.create(engine.PlayerEntity, { + runSpeed: 10, + jumpHeight: 2, +}) +``` + +The following properties are available: + +- `walkSpeed`: The speed at which the player walks, in meters per second. On the desktop client, players walk by pressing the control key. +- `jogSpeed`: The speed at which the player jogs, in meters per second. This is the default way in which the player moves. +- `runSpeed`: The speed at which the player runs, in meters per second. On the desktop client, players run by pressing the shift key. +- `jumpHeight`: The height at which the player jumps, in meters. +- `runJumpHeight`: The height at which the player jumps after running, in meters. +- `hardLandingCooldown`: The cooldown after a hard landing, in seconds. This is the time that the player has to wait before they can move again after landing from a high fall. + +For reference, here are the default values for those properties: + +- `walkSpeed`: 1.5 m/s +- `jogSpeed`: 8 m/s +- `runSpeed`: 10 m/s +- `jumpHeight`: 1 m +- `runJumpHeight`: 1.5 m +- `hardLandingCooldown`: 0.75 s + +{{< hint info >}} +**💡 Tip**: None of these properties can be lower than 0. If you set one of them to a negative value, it will be clamped to 0. Setting these values to zero will have the same effect as using the `InputModifier` to block the use of certain keys. + +You can only affect the player's locomotion if they are inside the scene's bounds. To affect other player's avatars, you must run the code that affects their locomotion on their own instance. +{{< /hint >}} + +You can create a [smart wearable]({{< ref "/content/creator/sdk7/projects/smart-wearables.md" >}}) that makes the player always run faster or jump higher. If both the scene and a smart wearable define different values for these parameters, the scene values are always used. + +To ensure nobody has unfair advantages at a parkour scene, you can enforce the default parameters by explicitly adding their default values in your scene: + +```ts +import {AvatarLocomotionSettings, engine} from '@dcl/sdk/ecs' + +AvatarLocomotionSettings.create(engine.PlayerEntity, { + runSpeed: 10, + walkSpeed: 1.5, + jogSpeed: 8 , + jumpHeight: 1, + runJumpHeight: 1.5, + hardLandingCooldown: 0.75 +}) +``` ## Avatar modifier areas @@ -470,4 +525,4 @@ See [NPC Avatars]({{< ref "/content/creator/sdk7/interactivity/npc-avatars.md" > **📔 Note**: To allow the player to have full control over that avatar, you should listen to button events to detect when they press a button, and then trigger the corresponding animation on the NPC avatar. See [Button Events]({{< ref "/content/creator/sdk7/interactivity/button-events/system-based-events.md" >}}) for more details. The fludity of control may not be perfect while doing this, you may want to use this only on very specific. -{{< /hint >}} \ No newline at end of file +{{< /hint >}}