GameCrew AIEarly access
Sign in
Godot 4physicsCompile-verified pattern

CharacterBody3D Slopes, Snap & Coyote Jump in Godot 4

Crisp Godot 4 CharacterBody3D locomotion combining floor_snap_length, apex hang gravity, jump-cut, coyote time, and zero-arg move_and_slide.

  • characterbody3d
  • platformer
  • physics
  • slopes
  • jump
  • coyote-time

When to Use & Field Best Practices

Default gravity integration with CharacterBody3D feels floaty at jump peaks and brittle when running fast over down-ramps or hitting jump two frames before landing:

  1. Configure Slope & Snap Properties Once in _ready(): Set floor_max_angle = deg_to_rad(45.0), floor_snap_length = 0.45, and floor_constant_speed = true, then call parameterless move_and_slide().
  2. Coyote Time + Jump Buffer + Apex Hang: Retain jump eligibility for ~0.11 s after stepping off ledges, buffer early jump presses ~0.12 s before touchdown, and cut upward gravity slightly near vertical speed zero for readable mid-air control.
  3. Variable Jump-Cut: If the player releases jump while still rising steeply, multiply upward velocity.y softly so short taps clear low gaps and held jumps reach high ledges cleanly.

Mathematical & Algorithmic Core

  • Initial Impulse from Target Jump Height $H$: $v_y,0 = √2 g H$
  • Apex Gravity Scaling: When |v_y| < v_apex, scale gravity by $0.58$ to extend hang time at jump apex without lengthening total fall duration.

Engine Implementation

Platformer CharacterBody3D Motor (Assets/Game/Scripts/player/platformer_motor.gd)

extends CharacterBody3D
## Responsive 3D platformer motor with slope snap, coyote time, jump buffer, and apex hang gravity.

const COYOTE_TIME := 0.11
const JUMP_BUFFER := 0.12
const APEX_SPEED := 2.2
const APEX_GRAV_MULT := 0.58

var view_yaw := 0.0
var _coyote_t := 0.0
var _jump_buf_t := 0.0
var _was_grounded := true
var _did_jump_cut := false


func _ready() -> void:
	floor_max_angle = deg_to_rad(45.0)
	floor_snap_length = 0.45
	floor_constant_speed = true
	floor_stop_on_slope = true


func _physics_process(delta: float) -> void:
	var gravity := Tuning.value("gravity", 24.0)
	var move_speed := Tuning.value("moveSpeed", 6.5)
	var accel := Tuning.value("acceleration", 40.0)
	var jump_height := Tuning.value("jumpHeight", 1.6)

	var move_in := GameInput.move()
	var dir := Vector3(move_in.x, 0.0, -move_in.y).rotated(Vector3.UP, view_yaw)
	var target_vel := dir * move_speed
	var flat := Vector3(velocity.x, 0.0, velocity.z).move_toward(target_vel, accel * delta)
	velocity.x = flat.x
	velocity.z = flat.z

	if dir.length_squared() > 0.01:
		rotation.y = lerp_angle(rotation.y, atan2(-dir.x, -dir.z), minf(1.0, 12.0 * delta))

	if is_on_floor():
		_coyote_t = COYOTE_TIME
		_did_jump_cut = false
		if velocity.y < 0.0:
			velocity.y = 0.0
	else:
		_coyote_t = maxf(0.0, _coyote_t - delta)
		var g_scale := APEX_GRAV_MULT if absf(velocity.y) < APEX_SPEED else 1.0
		velocity.y -= gravity * g_scale * delta

	if GameInput.pressed("jump"):
		_jump_buf_t = JUMP_BUFFER
	else:
		_jump_buf_t = maxf(0.0, _jump_buf_t - delta)

	if _jump_buf_t > 0.0 and _coyote_t > 0.0:
		velocity.y = sqrt(2.0 * gravity * jump_height)
		_jump_buf_t = 0.0
		_coyote_t = 0.0
		GameAudio.play("jump")
		Playtest.log_event("jump")

	if velocity.y > 1.5 and not GameInput.held("jump") and not _did_jump_cut:
		velocity.y *= 0.55
		_did_jump_cut = true

	move_and_slide()

	if is_on_floor() and not _was_grounded:
		GameAudio.play("land")
	_was_grounded = is_on_floor()

WebGL & Physics Consistency

  • Avoid Godot 3 Signatures: Always pass zero arguments to move_and_slide(); slope angle, up direction (Vector3.UP), and snap length live on properties of CharacterBody3D.
  • Keep Tuning Knobs Aligned with level.json: Read "gravity", "moveSpeed", "acceleration", and "jumpHeight" from Tuning.value so slider tweaks update jump height live.

Verification Checklist

  1. Run a play test jumping onto a raised platform both while moving uphill and tapping jump 3 frames before landing — confirm coyote and buffered jumps never drop.
  2. Confirm godot compile and godot lint report 0 errors and 0 warnings.

Official references

  • Godot 4 CharacterBody3D Physics Notes
  • Maddy Thorson (Celeste Movement & Coyote Time Feel)

Playable Godot 4 games made with GameCrew

Launch a real browser build using this engine and inspect its controls or fork its project tree.

Fernlight — Raise a carved whistle to your lips in a fog-drowned forest, coax a glowing bird onto your open hand, and point to send it off to light the dark.
Plays in VR

Fernlight

Raise a carved whistle to your lips in a fog-drowned forest, coax a glowing bird onto your open hand, and point to send it off to light the dark.

More Godot 4 techniques

ai

Context Steering, Patrol Paths & Telegraphed Enemy Encounters in Godot 4 →

Typed GDScript 4 context steering, LevelData patrol-path following, line-of-sight perception with memory hysteresis, attack-token pacing, and telegraphed combat state machines.

gameplay

Frame-Rate-Independent Springs, Squash-Stretch & Ribbon Trails in Godot 4 →

Typed GDScript 4 second-order damped springs, volume-preserving visual squash-stretch, Eiserloh T^2 FastNoiseLite camera trauma, and ImmediateMesh sword/dash ribbon trails.

water

Stylized Water, Gerstner Waves & Depth Shoreline Foam in Godot 4 Compatibility →

Godot 4.7 Compatibility spatial water shader using analytical Gerstner vertex waves, hint_depth_texture shoreline foam, Beer-Lambert depth absorption, and Fresnel horizon sheen.

atmosphere

Raymarched Volumetric Cloud Sky in Godot 4 Compatibility (WebGL 2) →

Compatibility-safe sky shader in Godot 4.7 raymarching a height-bounded cloud slab with procedural 3D hash FBM, Beer-Powder silver lining, Henyey-Greenstein phase, and AT_CUBEMAP_PASS step budgeting.

Use verified techniques inside a real game

Describe your game idea for free or connect an MCP assistant to search and contribute techniques.

Learn about collaboration