> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/tou-xiang/locomotion.md). Agents can also search and read this documentation through its [MCP server](https://docs.decentraland.org/~gitbook/mcp).

# 移动设置与限制

更改玩家的速度和跳跃高度，或限制他们的移动方式

你可以更改玩家在场景内移动时的化身动作。使用 `AvatarLocomotionSettings` 组件来调整速度和跳跃高度，并使用 `InputModifier` 组件来冻结玩家或阻止特定类型的移动。这两个组件都要添加到 `engine.PlayerEntity`上，并且只有玩家位于场景边界内时才会生效。

## 移动设置

你可以调整玩家的移动方式，例如跑步速度、跳跃高度等。这些设置可以动态更改，例如允许玩家通过与物品互动来获得临时加速，或在短时间内禁用玩家的跳跃能力。

{% hint style="info" %}
**💡 提示**：无需编写代码即可设置这些值。将 **移动设置** 智能物品拖入 [Creator Hub 中的场景编辑器](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/ru-men/about-editor.md) 并调整滑块。请参阅 [移动设置](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/jiao-hu-xing/smart-items.md#locomotion-settings).
{% endhint %}

要进行此设置，请将 `AvatarLocomotionSettings` 组件添加到 `engine.PlayerEntity`.

```ts
import {AvatarLocomotionSettings, engine} from '@dcl/sdk/ecs'

AvatarLocomotionSettings.create(engine.PlayerEntity, {
	runSpeed: 10,
	jumpHeight: 2,
})
```

可用属性如下：

* `walkSpeed`：玩家行走的速度，单位为米/秒。在桌面客户端中，玩家按住 Ctrl 键即可行走。
* `jogSpeed`：玩家慢跑的速度，单位为米/秒。这是玩家移动的默认方式。
* `runSpeed`：玩家跑步的速度，单位为米/秒。在桌面客户端中，玩家按住 Shift 键即可跑步。
* `jumpHeight`：玩家跳跃的高度，单位为米。
* `runJumpHeight`：玩家跑步后跳跃的高度，单位为米。
* `doubleJumpHeight`：二段跳时第二次跳跃的高度，单位为米。
* `glidingSpeed`：玩家滑翔时的水平移动速度，单位为米/秒。
* `glidingFallingSpeed`：玩家滑翔时的最大下落速度，单位为米/秒。此属性只限制玩家的下落速度：向上的运动（例如场景持续施力产生的升力）不受限制。
* `hardLandingCooldown`：重着陆后的冷却时间，单位为秒。玩家从高处坠落着陆后，必须等待这段时间才能再次移动。

以下是这些属性的默认值，供参考：

* `walkSpeed`：1.5 米/秒
* `jogSpeed`：8 米/秒
* `runSpeed`：10 米/秒
* `glidingSpeed`: 6 米/秒
* `glidingFallingSpeed`: 1 米/秒
* `jumpHeight`: 1 米
* `runJumpHeight`: 1.5 米
* `doubleJumpHeight`: 2 米
* `hardLandingCooldown`: 0.75 秒

{% hint style="info" %}
**💡 提示**: 滑翔时，场景施加的持续力会增强 1.5 倍，向上的力还可以将玩家托起。请参阅 [滑翔时的力](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/player-physics.md#forces-while-gliding).
{% endhint %}

{% hint style="info" %}
**💡 提示**: 这些属性的值都不能小于 0。如果将其中任何一项设为负值，该值会被限制为 0。将这些值设为 0，效果与使用 `InputModifier` 来阻止使用某些按键相同。

只有当玩家位于场景边界内时，才能影响其移动。若要影响其他玩家的角色，必须在他们各自的实例上运行影响其移动的代码。
{% endhint %}

你可以创建一个 [智能穿戴设备](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/xiang-mu-lei-xing/smart-wearables.md) 让玩家始终跑得更快或跳得更高。如果场景和智能穿戴设备为这些参数定义了不同的值，则始终使用场景中的值。

为确保玩家在跑酷场景中不会获得不公平的优势，你可以在场景中显式添加这些参数的默认值：

```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
})
```

## 限制移动方式

你可以限制玩家在场景中可执行的操作。你可以借此冻结玩家，或限制特定的移动方式，例如阻止玩家跳跃或奔跑。

### 冻结玩家

你可以冻结玩家，使任何输入按键都无法移动角色。这对许多游戏机制都很有用。此外，在播放不应被移动打断的重要动画时，或在 [虚拟摄像机](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/3d-nei-rong-ji-chu/camera.md) 背离角色且你不希望玩家在看不见的情况下移动时，冻结玩家也是一种好做法。

使用 `InputModifier` 组件，并将其添加到 `engine.PlayerEntity` 上，以防止玩家的输入影响角色的移动。角色将保持静止，玩家只能旋转摄像机。

```ts
import {InputModifier, engine} from '@dcl/sdk/ecs'

InputModifier.create(engine.PlayerEntity, {
	mode: InputModifier.Mode.Standard({
		disableAll: true,
	}),
})
```

请牢记以下注意事项：

* 玩家的交互被禁用时，其化身仍会受到外力影响，例如重力或移动平台的作用。
* 该 `InputModifier` 组件只能与 `engine.PlayerEntity` 实体。它只能影响当前玩家，不能影响其他玩家。
* 此组件仅在玩家的虚拟形象位于场景范围内时影响该玩家。玩家离开场景后，其移动限制会立即解除。
* 禁用玩家交互后，玩家无法自由使用表情动作，但场景仍可触发虚拟形象的动画。
* 玩家输入不会影响虚拟形象，但 [全局输入事件](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/an-niu-shi-jian/system-based-events.md#global-input-events) 仍可由场景监听。你可以用这些事件来控制载具，或者使用 [虚拟摄像机](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/3d-nei-rong-ji-chu/camera.md) 跟随其他实体的移动，将其视为替代虚拟形象。

### 限制特定类型的移动

除了完全冻结玩家之外，你还可以限制玩家的某些特定移动方式。例如，出于游戏玩法的考虑，可以禁用二段跳和滑翔，以保持平台游戏的难度。你甚至可以将这些能力作为游戏机制动态切换，例如为玩家设置耐力条，并在耐力耗尽时禁止奔跑。你也可以借此营造场景氛围，例如在宁静的场所禁止奔跑或跳跃。该 `InputModifier` 包含以下选项：

* `disableWalk`：玩家不能慢走（按住 Control 键）。如果允许，玩家尝试慢走时会改为慢跑或奔跑。
* `disableRun`：玩家不能奔跑（按住 Shift 键）。如果允许，玩家尝试奔跑时会改为慢跑。
* `disableJog`：玩家不能慢跑（这是默认移动速度）。如果允许，玩家尝试慢跑时会改为奔跑或慢走。
* `disableJump`：玩家不能跳跃。
* `disableEmote`：玩家不能主动使用表情动作。场景仍可触发玩家虚拟形象的动画。
* `disableDoubleJump`：玩家不能进行二段跳。
* `disableGliding`：玩家不能滑翔。

```ts
import {InputModifier, engine} from '@dcl/sdk/ecs'

InputModifier.create(engine.PlayerEntity, {
	mode: InputModifier.Mode.Standard({
		disableAll: false,
		disableWalk: false,
		disableRun: true,
		disableJog: true,
		disableJump: true,
		disableEmote: true,
		disableDoubleJump: true,
		disableGliding: true
	}),
})
```

### 高级语法

若要不使用任何辅助工具来使用此组件，可以采用以下语法：

```ts
import {InputModifier, engine} from '@dcl/sdk/ecs'

InputModifier.createOrReplace(engine.PlayerEntity, {
	mode: {
		$case: 'standard',
		standard: {
			disableAll: false,
			disableWalk: false,
			disableRun: true,
			disableJog: true,
			disableJump: true,
			disableEmote: true,
		},
	},
})
```

{% hint style="info" %}
**💡 提示**：如需查看可运行的示例，请参阅 [`0,1-input-modifier`](https://github.com/decentraland/sdk7-test-scenes/tree/main/scenes/0,1-input-modifier) 测试场景。该场景会分别切换每个 `InputModifier` 移动标志，并展示玩家移动受阻时，虚拟形象仍会被移动平台带着移动。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/jiao-hu-xing/tou-xiang/locomotion.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
