All skills
thedivergentai avatar

/godot-2d-physics

@9d6e91e

Expert patterns for Godot 2D physics including collision layers/masks, Area2D triggers, raycasting, and PhysicsDirectSpaceState2D queries. Use when implementing collision detection, trigger zones, line-of-sight systems, or manual physics queries. Trigger keywords: CollisionShape2D, CollisionPolygon2D, collision_layer, collision_mask, set_collision_layer_value, set_collision_mask_value, Area2D, body_entered, body_exited, RayCast2D, force_raycast_update, PhysicsPointQueryParameters2D, PhysicsShapeQueryParameters2D, direct_space_state, move_and_collide, move_and_slide.

Use this Skill: https://skilld.dev/gh/thedivergentai/gd-agentic-skills/godot-2d-physics

This session only. Nothing lands on disk.

referencescollision-layers-masks.md

≈413 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Collision layers and masks

Mental model

# collision_layer: What broadcast channels am I transmitting on?
# collision_mask:   What broadcast channels am I listening to?

# Player: layer=0b0001, mask=0b0110 (hears enemies + world)
# Enemy:  layer=0b0010, mask=0b0101 (hears player + world)

Layer = who I am. Mask = who I detect. Setting both to the same value is usually wrong.

Helpers (prefer over magic bitmasks)

func setup_player_collision() -> void:
    set_collision_layer_value(1, true)   # I am layer 1
    set_collision_mask_value(2, true)    # Detect enemies
    set_collision_mask_value(3, true)    # Detect world

func enable_layers(base_layer: int, count: int) -> void:
    var mask := 0
    for i in range(count):
        mask |= (1 << (base_layer + i - 1))
    collision_mask = mask

Scripts: collision_bitmask_helper.gd, collision_layer_matrix_manager.gd.

Common patterns

# Projectile hits enemies, ignores other projectiles
extends Area2D
func _ready() -> void:
    set_collision_layer_value(4, true)  # Projectiles
    set_collision_mask_value(2, true)   # Enemies only

Name layers in Project Settings before hardcoding layer indices in team docs.

Edge cases

Issue Fix
Raycast false in _ready() await get_tree().physics_frame first
CharacterBody2D not seen by Area2D Default collision_layer = 0 — set layer explicitly
One-way platforms Godot 4.7: body_set_shape_as_one_way_collision with shape-relative direction

Source: SKILL.md on GitHub

1 warning16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides expert patterns for Godot 2D physics, including collision layers, raycasting, and performance optimization. No malicious patterns, obfuscation, or unauthorized data access were detected. All external links point to official Godot documentation or the verified author's GitHub repository.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    5/6 files flagged

Signed by skilld at 9d6e91e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 weeks ago.

Activeupdated 2 months ago

README badge

README badge for thedivergentai/gd-agentic-skills/godot-2d-physics