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.

referencesarea2d-and-queries.md

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

Area2D patterns and manual queries

Multi-shape duplicate body_entered

CAUTION: If an Area2D has multiple CollisionShape2D children, body_entered fires once per shape — pickups trigger 3×, damage applies 3×.

# BAD — no dedupe
func _on_body_entered(body: Node2D) -> void:
    body.take_damage(10)  # Fires per shape!

# GOOD — track unique bodies (or use collision_debouncer.gd)
var _active_bodies := {}

func _on_body_entered(body: Node2D) -> void:
    if body in _active_bodies:
        return
    _active_bodies[body] = true
    body.take_damage(10)

func _on_body_exited(body: Node2D) -> void:
    _active_bodies.erase(body)

Damage-over-time zones

Per-body tick timers in _process — do not poll get_overlapping_bodies() every frame. See lava pattern in baseline; prefer signals + timer dict.

RayCast2D

func can_see_target(target: Node2D) -> bool:
    var direction := global_position.direction_to(target.global_position)
    vision_ray.target_position = direction * 300
    vision_ray.force_raycast_update()  # REQUIRED after mid-frame target change
    return vision_ray.is_colliding() and vision_ray.get_collider() == target

Ledge check: front ray hits floor, back ray does not → at_ledge().

Exclusions: add_exception(self) on weapon/child colliders.

PhysicsDirectSpaceState2D

Task API
Click pick PhysicsPointQueryParameters2D + intersect_point
AOE PhysicsShapeQueryParameters2D + intersect_shape
Hitscan PhysicsRayQueryParameters2D.create(from, to) + exclude

Canonical samples: physics_queries.gd, raycast_vision_stack.gd, shapecast_aoe.gd.

Performance

Elite: compound RID bodies

Multiple shapes on one PhysicsServer2D body RID — compound_body_sync.gd.

Debug draw

Contact normals/points from KinematicCollision2D — collision_visual_debugger.gd.

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