Godot: Jolt, CharacterBody3D and AnimationTree
Godot 4 ships two 3D physics engines. Godot Physics is the original built-in one. Jolt Physics, the open-source engine also used in large commercial games, was integrated in Godot 4.4 as an experimental option and became the default for new 3D projects in Godot 4.6. Projects created earlier keep their setting, and you choose under Project Settings > Physics > 3D > Physics Engine. 2D physics is always Godot's own. The GDScript here is real Godot 4 code (not run on the site); the C++ block models one of its features. For the engine itself, see Godot 4 with GDScript.
Switching to Jolt: what changes
Jolt is generally faster and more stable with many bodies and stacks, but it is a different solver, so a project that switches should be retested. Differences worth knowing, from the Godot docs:
- many soft-limit properties of the 3D joint nodes are not supported (you get a warning if you change them);
- collision margins shrink the shape first, so shapes don't grow;
- position correction doesn't add velocity, so bodies don't "pop" out of overlaps;
- contact impulses reported to scripts are estimates;
WorldBoundaryShape3Dis effectively much smaller than the infinite plane of Godot Physics, so use a large box for big floors.
Bodies
| Course concept | Godot node / API |
|---|---|
| static body | StaticBody3D |
| dynamic body | RigidBody3D: linear_velocity, apply_central_impulse(), apply_impulse(impulse, position), apply_central_force() |
| kinematic body you move by code | AnimatableBody3D (moving platforms), CharacterBody3D (characters) |
| material | PhysicsMaterial with friction, bounce (physics_material_override) |
| CCD | continuous_cd = true |
| sleeping | can_sleep, sleeping |
| custom integration | _integrate_forces(state) with PhysicsDirectBodyState3D |
| filtering | collision_layer (what I am) and collision_mask (what I hit) |
| triggers | Area3D with body_entered / body_exited |
Queries go through the space state, from inside _physics_process:
var space := get_world_3d().direct_space_state
var query := PhysicsRayQueryParameters3D.create(muzzle.global_position,
muzzle.global_position - muzzle.global_basis.z * 100.0, 0b0101, [get_rid()])
var hit := space.intersect_ray(query)
if hit:
print(hit.collider, hit.position, hit.normal)RayCast3D and ShapeCast3D nodes do the same thing every physics frame without code, which is handy for ground checks and line of sight.
CharacterBody3D
CharacterBody3D is a kinematic body with velocity and move_and_slide(): collide and slide, slope handling and floor snapping, run once per physics tick.
extends CharacterBody3D
@export var speed := 5.0
@export var jump_velocity := 4.5
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_velocity
var input := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
var direction := (transform.basis * Vector3(input.x, 0, input.y)).normalized()
velocity.x = direction.x * speed
velocity.z = direction.z * speed
move_and_slide()Its floor settings, with their defaults:
| Property | Default | Meaning |
|---|---|---|
up_direction |
Vector3(0, 1, 0) |
what "up" is (change it for wall walking or planets) |
floor_max_angle |
45° (0.785 rad) | steeper surfaces count as walls |
floor_snap_length |
0.1 | how far down to search for the floor to stick to |
floor_stop_on_slope |
true |
standing still on a slope doesn't slide |
floor_constant_speed |
false |
true keeps the same speed up and down slopes |
floor_block_on_wall |
true |
walls don't let you climb them |
max_slides |
6 | collide-and-slide iterations per call |
safe_margin |
0.001 | skin distance used in collision recovery |
There is no built-in step-up: stairs need a ramp-shaped collider, or your own step logic (a shape cast forward and down, as in Slopes, Steps and Ground Snapping).
Floor snap length is a speed limit
Floor snapping keeps the body glued to the ground when the ground drops away under it, but only within floor_snap_length per tick. Over a crest at speed, the ground falls by speed · dt · tan(slope) each tick; if that exceeds the snap length, the character goes airborne for a moment, is_on_floor() turns false, and the jump button stops working. A 2D model at 60 ticks per second:
#include <iostream>
#include <iomanip>
#include <cmath>
// Flat ground up to x = 1, then a downhill slope. Returns how many ticks the character spent in the air.
int airborneTicks(double slopeDeg, double speed, double snapLength) {
const double dt = 1.0 / 60, g = 9.8, pi = 3.141592653589793;
double slope = std::tan(slopeDeg * pi / 180);
auto ground = [&](double x) { return x < 1 ? 0.0 : -(x - 1) * slope; };
double x = 0, y = 0, vy = 0;
bool onFloor = true;
int air = 0;
for (int tick = 0; tick < 120; tick++) {
if (!onFloor) vy -= g * dt;
x += speed * dt;
y += vy * dt;
double gap = y - ground(x);
if (gap <= 0) { y = ground(x); vy = 0; onFloor = true; } // landed
else if (onFloor && gap <= snapLength) { y = ground(x); vy = 0; } // snapped down
else onFloor = false;
if (!onFloor) air++;
}
return air;
}
int main() {
std::cout << std::fixed << std::setprecision(3);
const double speed = 6.0;
for (double deg : {20.0, 30.0, 45.0})
for (double snap : {0.0, 0.1, 0.2})
std::cout << "slope " << deg << " deg, drop per tick " << speed / 60 * std::tan(deg * 3.141592653589793 / 180)
<< ", snap " << snap << ": " << airborneTicks(deg, speed, snap) << " ticks in the air\n";
}slope 20.000 deg, drop per tick 0.036, snap 0.000: 107 ticks in the air
slope 20.000 deg, drop per tick 0.036, snap 0.100: 0 ticks in the air
slope 20.000 deg, drop per tick 0.036, snap 0.200: 0 ticks in the air
slope 30.000 deg, drop per tick 0.058, snap 0.000: 108 ticks in the air
slope 30.000 deg, drop per tick 0.058, snap 0.100: 0 ticks in the air
slope 30.000 deg, drop per tick 0.058, snap 0.200: 0 ticks in the air
slope 45.000 deg, drop per tick 0.100, snap 0.000: 109 ticks in the air
slope 45.000 deg, drop per tick 0.100, snap 0.100: 74 ticks in the air
slope 45.000 deg, drop per tick 0.100, snap 0.200: 0 ticks in the air
The model runs for two seconds (120 ticks), the first 10 on flat ground. With no snap, the character spends almost all of the rest in the air: it leaves the crest, lands, and immediately leaves the slope again, a string of tiny hops. With the default 0.1 it stays grounded on 20° and 30° slopes at 6 m/s, but on 45° the ground drops a hair more than 0.1 m per tick and it is airborne for 74 ticks. Rule of thumb: floor_snap_length must be larger than max_speed / ticks_per_second · tan(floor_max_angle). Godot disables snapping while you move upward, so jumps still leave the ground; apply_floor_snap() forces a snap after a teleport or a landing you handle yourself.
Physics ticks and interpolation
_physics_process runs at Physics Ticks per Second (Project Settings > Physics > Common, 60 by default), _process once per rendered frame. Turn on Physics Interpolation in the same section to draw bodies between ticks, exactly like Fixed Timestep and Interpolation. After teleporting a node, call reset_physics_interpolation() so it doesn't glide from its old position.
Animation: AnimationTree and IK
AnimationPlayer holds clips; AnimationTree blends them with state machines, BlendSpace1D/BlendSpace2D (blend trees) and blend nodes. Parameters are set by path:
@onready var tree: AnimationTree = $AnimationTree
@onready var playback: AnimationNodeStateMachinePlayback = tree.get("parameters/playback")
func _process(_delta: float) -> void:
tree.set("parameters/Locomotion/blend_position", Vector2(velocity.x, velocity.z).length())
if Input.is_action_just_pressed("jump"):
playback.travel("Jump") # walks the state machine graph to the Jump state- Root motion: set the tree's
root_motion_trackto the root bone, then turnget_root_motion_position()(a per-frame delta) into a velocity:velocity = global_transform.basis * tree.get_root_motion_position() / deltabeforemove_and_slide(). - Animation events: Call Method tracks call a function at an exact frame (footsteps, hit windows);
animation_finishedfires at the end of a clip. - IK: Godot 4.6 brought a new IK framework built on
SkeletonModifier3D:IKModifier3DwithTwoBoneIK3D,SplineIK3D,FABRIK3D,CCDIK3DandJacobianIK3D, plus joint constraints. The olderSkeletonIK3Dnode is deprecated. - Ragdolls:
PhysicalBone3Dnodes under aPhysicalBoneSimulator3D, generated from the Skeleton3D's menu.
Test yourself
Since which Godot version is Jolt the default physics engine for new 3D projects?
- 4.0
- 4.4
- 4.6
- It is never the default
A character at 9 m/s on 60 ticks per second goes airborne on a 35° downhill. What is the most direct fix?
- Lower
max_slides - Raise
floor_snap_lengthabove the per-tick ground drop (about 0.105 m) - Turn off
floor_stop_on_slope - Use
_processinstead
How do you climb stairs with CharacterBody3D?
- Set
floor_max_angleto 90° - There is no built-in step-up: use ramp colliders or your own step logic
- Enable
floor_constant_speed - Raise
safe_margin