thedivergentai/gd-agentic-skills

godot-2d-physics

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, PhysicsShap…

First seen Feb 10, 2026

Installation

$ npx skills add thedivergentai/gd-agentic-skills --skill godot-2d-physics

Summary

  • 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.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from thedivergentai/gd-agentic-skills · top by installs.

npx skills add thedivergentai/gd-agentic-skills

Browse all from thedivergentai/gd-agentic-skills

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 678
License LICENSE
Default branch main
Open issues 0
Status Active

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 16,061 B
  • docs SUMMARY.md 4,007 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 398 installs

SKILL.md

2D Physics

Expert guidance for collision detection, triggers, and raycasting in Godot 2D.

NEVER Do

  • NEVER scale CollisionShape2D nodes — Use the shape handles in the editor, NOT the Node2D scale property. Scaling causes unpredictable physics behavior and incorrect collision normals [12].
  • NEVER confuse collisionlayer with collisionmask — Layer = "What AM I?", Mask = "What do I DETECT?". Setting both to the same value is usually wrong [13].
  • NEVER multiply velocity by delta when using moveandslide()moveandslide() automatically includes timestep. Only multiply gravity/acceleration by delta [14].
  • NEVER forget forceraycastupdate() for manual mid-frame raycasts — Raycasts update once per physics frame. If you change target_position, you MUST force an update [15].
  • NEVER use getoverlappingbodies() every frame — It is expensive. Cache results with bodyentered/bodyexited signals instead [16].
  • NEVER modify RigidBody2D state directly in process — Use integrate_forces() for safe, synchronized access to PhysicsDirectBodyState2D [17, 411].
  • NEVER move PhysicsBody2D nodes in process() — Use physics_process(). Moving bodies outside the physics step causes stutter and unreliable collision detection.
  • NEVER use RigidBody2D for 1000+ simple entities — Use PhysicsServer2D to bypass node overhead for massive performance gains (Swarms/Bullets) [18, 397].
  • NEVER use Area2D for high-frequency blocking (Bullets) — Area signals can be delayed. Use moveandcollide() or ShapeCast2D for frame-perfect results [19].
  • NEVER ignore 'Physics Jitter' on high-refresh monitors — Enable Physics Interpolation to prevent micro-stutter in motion [21, 400].
  • NEVER scale collision shapes directly at runtime — It causes major instability. Resize the shape resource (size/radius) instead.
  • NEVER use setdeferred for immediate physics transform logic — It happens at the end of the frame. Use forceraycast_update() or PhysicsServer2D instead.
  • NEVER leave Continuous CD (CCD) enabled for slow objects — It adds significant CPU overhead. Reserve it for high-speed projectiles to prevent tunneling.
  • NEVER use a single collision layer for all tiles/entities — Separate layers (Ground, Walls, Enemies) to allow selective filtering via masks.
  • NEVER forget to free PhysicsServer2D RIDs manually — They are not garbage collected and will leak memory permanently.

Available Scripts

MANDATORY: Read the script matching your workflow branch before coding. Query/Area cookbook samples live in scripts — not in this body.

Workflow router (MANDATORY / Do NOT Load)

Branch Load Do NOT Load
Layer/mask matrix setup collisionbitmaskhelper.gd or collisionsetup.gd; matrix policy → collisionlayermatrixmanager.gd Swarm / CCD scripts
LOS / vision cones raycastvisionstack.gd (+ physicsdirectquery.gd for nodeless rays) shapecastaoe*.gd, physicsserver_swarm.gd
AOE / melee volume Prefer shapecastaoe.gd (faction mask); ground/volume sensing → shapecastaoe_detection.gd Area2D spam + lava DoT tutorials; do not load both shapecast scripts for the same feature
Hitscan / point pick / one-shot shape physicsqueries.gd (canonical). Specialists: physicsdirectspacequery.gd (LOS bool), raycasthitprediction.gd Re-load all three query helpers at once
Bullet hell / 1000+ bodies MANDATORY physicsserverswarm.gd (+ physicsserverdirect_body.gd for RID shapes) Per-bullet Area2D / RigidBody2D nodes
High-speed tunneling continuouscollisiondetection.gd + substepping_logic.gd CCD on slow props
RigidBody safe mutate saferigidbodystate.gd (integrateforces) Direct transform writes in _process
Custom CharacterBody forces customphysics2d.gd customphysics.gd (that file is RigidBody integrate_forces)
Gravity zones customgravityarea.gd (Area override) or customgravityoverride.gd (character weight/zones) Both unless you need Area + character paths
Overlap signal spam collision_debouncer.gd Polling getoverlappingbodies every frame
Compound multi-shape RID compoundbodysync.gd Multiple nodes for one logical body
Debug contact normals collisionvisualdebugger.gd Visible collision menu insufficient
High-refresh jitter Prefer jitterinterpolationfix.gd physicsinterpolationsmoothing.gd (legacy/manual; only if built-in interpolation is unavailable)
Precision bounce / slide moveandcollide_precision.gd
Batch static movers performancebatchmover.gd
Query result cache physicsquerycache.gd Duplicate space queries same frame

Canonical vs overlap (dedupe guide)

  • ShapeCast AOE: load shapecastaoe.gd for combat AOE; shapecastaoe_detection.gd only for grounded/volume checks — never both for one feature.
  • Space queries: start with physicsqueries.gd; add physicsdirectquery.gd / physicsdirectspacequery.gd only if that specialist matches.
  • Custom physics: CharacterBody → customphysics2d.gd; RigidBody integrate → custom_physics.gd.
  • Interpolation: jitterinterpolationfix.gd wins over physicsinterpolationsmoothing.gd.

Script index

  • [collisionsetup.gd](scripts/collisionsetup.gd) / [collisionbitmaskhelper.gd](scripts/collisionbitmaskhelper.gd) / [collisionlayermatrixmanager.gd](scripts/collisionlayermatrixmanager.gd)
  • [physicsqueries.gd](scripts/physicsqueries.gd) / [physicsdirectquery.gd](scripts/physicsdirectquery.gd) / [physicsdirectspacequery.gd](scripts/physicsdirectspacequery.gd) / [physicsquerycache.gd](scripts/physicsquerycache.gd)
  • [raycastvisionstack.gd](scripts/raycastvisionstack.gd) / [raycasthitprediction.gd](scripts/raycasthitprediction.gd)
  • [shapecastaoe.gd](scripts/shapecastaoe.gd) / [shapecastaoedetection.gd](scripts/shapecastaoedetection.gd)
  • [physicsserverswarm.gd](scripts/physicsserverswarm.gd) / [physicsserverdirectbody.gd](scripts/physicsserverdirectbody.gd)
  • [continuouscollisiondetection.gd](scripts/continuouscollisiondetection.gd) / [substeppinglogic.gd](scripts/substeppinglogic.gd)
  • [saferigidbodystate.gd](scripts/saferigidbodystate.gd) / [customphysics.gd](scripts/customphysics.gd) / [customphysics2d.gd](scripts/customphysics2d.gd)
  • [customgravityarea.gd](scripts/customgravityarea.gd) / [customgravityoverride.gd](scripts/customgravityoverride.gd)
  • [collisiondebouncer.gd](scripts/collisiondebouncer.gd) / [jitterinterpolationfix.gd](scripts/jitterinterpolationfix.gd)
  • [compoundbodysync.gd](scripts/compoundbodysync.gd) / [collisionvisualdebugger.gd](scripts/collisionvisualdebugger.gd)
  • [moveandcollideprecision.gd](scripts/moveandcollideprecision.gd) / [performancebatchmover.gd](scripts/performancebatchmover.gd)
  • [physicsinterpolationsmoothing.gd](scripts/physicsinterpolationsmoothing.gd) — legacy; prefer jitter fix script

Decision Tree: Collision Detection Methods

Use Case Method Why / script
Continuous trigger zone Area2D + signals Memory of occupants; debounce with collision_debouncer.gd
One-time pickup Area2D + queue_free on enter Simple cleanup
Line-of-sight RayCast2D / direct ray raycastvisionstack.gd or physicsdirectquery.gd
Click-to-select PhysicsPointQueryParameters2D physics_queries.gd
AOE spell / melee volume ShapeCast2D / shape query shapecast_aoe.gd (not Area signal lag)
Instant-hit weapon PhysicsRayQueryParameters2D physicsqueries.gd / raycasthit_prediction.gd
Platformer ground / ledge Ray or ShapeCast down CharacterBody skill + shapecastaoedetection.gd
1000+ projectiles PhysicsServer2D RIDs MANDATORY physicsserverswarm.gd

Mental model (keep short)

  • Layer = who I am; Mask = who I detect. Bitmask cookbook → [collision-layers-masks.md](references/collision-layers-masks.md).
  • Area2D with multiple shapes fires bodyentered once per shape — dedupe with a Set/dict or [collisiondebouncer.gd](scripts/collision_debouncer.gd).
  • Mid-frame ray/shape changes require forceraycastupdate() / forceshapecastupdate().
  • ready physics queries are false until after a physics frame (await gettree().physics_frame).
  • CharacterBody2D ships with collision_layer = 0 — Areas won't see it until you set a layer.
  • Free PhysicsServer RIDs yourself — they are not GC'd.

Deep recipes (on demand)

Topic Reference / script
Layer/mask patterns [collision-layers-masks.md](references/collision-layers-masks.md)
Area2D, raycast, shape queries [area2d-and-queries.md](references/area2d-and-queries.md)
Compound RID bodies [compoundbodysync.gd](scripts/compoundbodysync.gd)
Contact normal debug draw [collisionvisualdebugger.gd](scripts/collisionvisualdebugger.gd)

Reference

Progressive disclosure: open Official Documentation links only when researching a specific API;
load Related Skills when routing work to a peer domain — do not preload the whole lattice.

Official Documentation

  • Physics introduction — Collision layers vs masks, body types, and the mental model every 2D setup depends on.
  • Collision shapes (2D) — Correct shape sizing and why scaling CollisionShape2D nodes breaks normals and contacts.
  • Using CharacterBody2Dmoveandslide / moveand_collide, floor detection, and kinematic movement contracts.
  • Using Area2D — Trigger monitoring, overlap signals, and space/gravity overrides for zones.
  • Ray-castingRayCast2D vs PhysicsDirectSpaceState2D rays, exclusions, and mid-frame forceraycastupdate.
  • RigidBody — Safe rigid-body control via integrateforces / PhysicsDirectBodyState2D instead of fighting the solver in process.
  • Troubleshooting physics issues — Tunneling, jitter, one-way platforms, and common layer/mask misconfigurations.
  • Physics interpolation introduction — Why fixed physics ticks stutter on high-refresh displays and when interpolation fixes it.
  • PhysicsServer2D — RID-based body/shape APIs for swarm-scale 2D physics without SceneTree overhead.
  • PhysicsDirectSpaceState2D — Point, ray, and shape queries for LOS, AOE, and click-picking without permanent query nodes.
  • ShapeCast2D — Volume casts for frame-perfect melee/AOE detection when Area2D signal lag is unacceptable.

Related Skills

Prerequisites

  • godot-project-foundations — Project Settings layer names, physics ticks, and default gravity must be set before layer/mask matrices stay sane.
  • godot-gdscript-mastery — Bitmask enums, typed dictionaries for overlap sets, and physicsprocess discipline underpin every pattern here.
  • godot-signal-architecturebodyentered / bodyexited wiring and debounce patterns need clean signal ownership to avoid spam.

Complements

  • godot-characterbody-2d — Coyote time, jump buffers, and one-way platforms sit on top of the collision contracts this skill defines.
  • godot-raycasting-queries — Deeper query parameter recipes (exclusions, masks, shape casts) when vision/hitscan systems grow beyond basics.
  • godot-tilemap-mastery — Tile physics layers and one-way tile collisions must match the same layer matrix used by bodies and areas.
  • godot-input-handling — Physics-step input sampling and vsync/latency choices couple tightly with moveandslide feel.
  • godot-physics-3d — Parallel 3D body/query concepts when porting or sharing layer policy across dimensions.
  • godot-performance-optimization — Profiling and batching guidance when PhysicsServer2D swarms or query caches become bottlenecks.
  • godot-debugging-profiling — Visible collision shapes, contact normals, and frame-time traps when diagnosing jitter or missed hits.

Downstream / consumers

  • godot-combat-system — Hitboxes/hurtboxes are Area2D + layer/mask products; damage timing inherits overlap and CCD choices.
  • godot-genre-platformer — Platformer feel (floors, ledges, one-ways) consumes CharacterBody2D + collision setup from this domain.
  • godot-navigation-pathfinding — Agents still need physics layers for blockers and LOS; keep nav meshes and collision worlds consistent.
  • godot-monte-carlo-balancer — Jump windows, projectile speed/CCD, gravity, and hitbox size directly change win-rate and difficulty curves; simulate those physics knobs instead of guessing.

Master

  • godot-master — Library router and mirrored entry point for discovering 2D physics alongside sibling domains.