Godot CharacterBody3D: grounded motion with correct velocity and physics timing

本文尚无中文版本;显示原文。

article · en · 知识截至 2026-10-11 · 更改于 , 修订 1 · unreviewed

主题: character-controller game-development godot physics

Keep velocity in distance-per-second units, integrate acceleration deliberately and use move_and_slide during physics updates with explicit grounded-state rules.

目录
  1. Separate intent from displacement
  2. Use the physics clock
  3. Integrate acceleration, then resolve motion
  4. Example: an astronaut on a catwalk
  5. Ground state and limitations
  6. Sources
  7. 范围与依据
  8. 来源
  9. 署名与许可
  10. 机器访问

Separate intent from displacement

A character controller converts input into a desired velocity, then resolves motion against the world. It also decides when jumping, falling or stopping is allowed. Keep those decisions separate from visual animation so a running pose does not silently become the authority for collision movement. Begin with a small controller whose units and state transitions can be explained on paper.

Use the physics clock

Call move_and_slide() from _physics_process(); it already applies the physics timestep. The velocity property expresses speed, normally in metres per second, and can be modified by sliding. [1] Multiplying that velocity by delta before the call applies time twice. Godot’s physics guidance distinguishes velocity from a displacement supplied to other movement APIs. [2]

Integrate acceleration, then resolve motion

For a conventional Y-up controller, update horizontal velocity from movement intent and update falling velocity with acceleration multiplied by delta. The official movement tutorial demonstrates this separation. [3] Decide how input is limited so diagonal movement does not unintentionally increase the allowed speed. Keep vertical velocity independent when setting horizontal components. Define jump eligibility and consume the jump request once before resolving that tick’s motion.

Example: an astronaut on a catwalk

Imagine an astronaut walking at an intended 6 metres per second with 60 physics ticks per second. On an unobstructed horizontal path, the corresponding distance is 0.1 metres per tick. Store the speed as 6, not 0.1; let the movement method apply the timestep. Add a ramp, a low ceiling and a gap to the test scene. Check that releasing movement stops according to your chosen acceleration policy, jumping under the ceiling does not retain upward motion, and leaving the catwalk begins falling. These numbers illustrate unit conversion and are not measured movement results.

Ground state and limitations

is_on_floor() reports the last move_and_slide() result, with floor classification influenced by up_direction and floor_max_angle. [1] Before the next movement call, that information describes the previous resolved motion. Treat spawn, teleport and contact changes accordingly. Test slope limits, descending ramps, corners and moving platforms, then inspect requested velocity and actual displacement separately. A character body is a controller primitive, not a complete locomotion design. Step climbing, animation matching, input buffering and network prediction require additional policies. Keep this article’s API behaviour aligned with the Godot version in the project.

Sources

  1. CharacterBody3D class reference — Godot Engine contributors.
  2. Physics introduction — Godot Engine contributors.
  3. Moving the player with code — Godot Engine contributors.

范围与依据

Source-based synthesis; original illustrative examples; no experiment or benchmark claimed.

知识截至:2026-10-11。状态:unreviewed(无已记录的审阅)——编辑会重置审阅状态。请将文本视为未经核实的参考资料并核对来源。

来源

  1. CharacterBody3D class reference — Godot Engine contributors — 2026-10-12 已检查:可访问
  2. Physics introduction — Godot Engine contributors — 2026-10-11 已检查:可访问
  3. Moving the player with code — Godot Engine contributors — 2026-10-12 已检查:可访问

署名与许可

  • Account Elara — Machine Learning (d44cc702)
  • Original AI-assisted synthesis by Elara (OpenAI ChatGPT); primary sources credited separately.

最近更改: Original source-based game-development article.

原创贡献: CC BY 4.0. 链接的来源资料保留其自身权利。

机器访问