Godot 2d physics

From thedivergentai/GD-Agentic-Skills · View interactive version

Godot 2d physics is an AI agent skill from the GitHub repository thedivergentai/GD-Agentic-Skills. 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, CollisionPolygon2

How to use this skill

Skill file

2D Physics

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

NEVER Do


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 | collision_bitmask_helper.gd or collision_setup.gd; matrix policy → collision_layer_matrix_manager.gd | Swarm / CCD scripts |

| LOS / vision cones | raycast_vision_stack.gd (+ physics_direct_query.gd for nodeless rays) | shapecast_aoe*.gd, physics_server_swarm.gd |

| AOE / melee volume | Prefer shapecast_aoe.gd (faction mask); ground/volume sensing → shapecast_aoe_detection.gd | Area2D spam + lava DoT tutorials; do not load both shapecast scripts for the same feature |

| Hitscan / point pick / one-shot shape | physics_queries.gd (canonical). Specialists: physics_direct_space_query.gd (LOS bool), raycast_hit_prediction.gd | Re-load all three query helpers at once |

| Bullet hell / 1000+ bodies | MANDATORY physics_server_swarm.gd (+ physics_server_direct_body.gd for RID shapes) | Per-bullet Area2D / RigidBody2D nodes |

| High-speed tunneling | continuous_collision_detection.gd + substepping_logic.gd | CCD on slow props |

| RigidBody safe mutate | safe_rigidbody_state.gd (_integrate_forces) | Direct transform writes in _process |

| Custom CharacterBody forces | custom_physics_2d.gd | custom_physics.gd (that file is RigidBody _integrate_forces) |

| Gravity zones | custom_gravity_area.gd (Area override) or custom_gravity_override.gd (character weight/zones) | Both unless you need Area + character paths |

| Overlap signal spam | collision_debouncer.gd | Polling get_overlapping_bodies every frame |

| Compound multi-shape RID | compound_body_sync.gd | Multiple nodes for one logical body |

| Debug contact normals | collision_visual_debugger.gd | Visible collision menu insufficient |

| High-refresh jitter | Prefer jitter_interpolation_fix.gd | physics_interpolation_smoothing.gd (legacy/manual; only if built-in interpolation is unavailable) |

| Precision bounce / slide | move_and_collide_precision.gd | — |

| Batch static movers | performance_batch_mover.gd | — |

| Query result cache | physics_query_cache.gd | Duplicate space queries same frame |

Canonical vs overlap (dedupe guide)

Script index


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 | raycast_vision_stack.gd or physics_direct_query.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 | physics_queries.gd / raycast_hit_prediction.gd |

| Platformer ground / ledge | Ray or ShapeCast down | CharacterBody skill + shapecast_aoe_detection.gd |

| 1000+ projectiles | PhysicsServer2D RIDs | MANDATORY physics_server_swarm.gd |


Mental model (keep short)

Deep recipes (on demand)

| Topic | Reference / script |

|-------|-------------------|

| Layer/mask patterns | collision-layers-masks.md |

| Area2D, raycast, shape queries | area2d-and-queries.md |

| Compound RID bodies | compound_body_sync.gd |

| Contact normal debug draw | collision_visual_debugger.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

Related Skills

Prerequisites
Complements
Downstream / consumers
Master
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.