Godot Physics Tutorial: Everything You Need to Know

Complete guide to Godot 4 physics. Covers body types, collision layers, raycasting, Jolt Physics in 4.6, and common physics patterns for 2D and 3D games.

Abstract physics and motion visualization

Physics in Godot is powerful yet approachable. Whether you're making a platformer, a physics puzzle, or a 3D shooter, understanding body types, collision layers, and raycasting is essential.

The Four Body Types

Every physics object in Godot is one of four types: StaticBody (walls/floors), RigidBody (physics-driven objects), CharacterBody (player-controlled), or Area (detection zones). Choose the right type and physics handles the rest.

gdscript
# CharacterBody2D — Player-controlled
extends CharacterBody2D

var gravity = 980.0

func _physics_process(delta):
    velocity.y += gravity * delta
    velocity.x = Input.get_axis("left", "right") * 200
    move_and_slide()

# RigidBody2D — Physics-driven
extends RigidBody2D

func _ready():
    # Apply initial force
    apply_impulse(Vector2(100, -200))

Collision Layers & Masks

Layer = what I AM. Mask = what I DETECT. Set player on layer 1, enemies on layer 2, bullets on layer 3. Player mask includes layer 2 (detects enemies). Enemy mask includes layer 3 (detects bullets). Simple, powerful, zero code needed.

Raycasting

gdscript
# Raycast for line-of-sight
func can_see_player():
    var space = get_world_2d().direct_space_state
    var query = PhysicsRayQueryParameters2D.create(
        global_position,
        player.global_position
    )
    var result = space.intersect_ray(query)
    return result and result.collider == player

Jolt Physics in 4.6

Godot 4.6 makes Jolt Physics the default 3D engine. Jolt offers better performance, more stable stacking, improved character controllers, and deterministic simulation. Existing projects keep their current engine — Jolt is default for NEW projects only.

👤
Godot Learning Team Helping developers transition to Godot with practical tutorials and comparisons.