godot-raycasting-queries

Implements Godot physics queries using RayCast, ShapeCast, and DirectSpaceState for hit detection and picking.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/DecioLuvier/Shatterless --skill godot-raycasting-queries-decioluvier
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: godot-raycasting-queries
Source: https://github.com/DecioLuvier/Shatterless/tree/main/.claude/skills/godot/references/godot-raycasting-queries
Command: npx skills add https://github.com/DecioLuvier/Shatterless --skill godot-raycasting-queries-decioluvier

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Choosing and correctly implementing the right physics query in Godot is error-prone: rays tunnel through thin walls, casters hit themselves, queries run outside the physics step, and developers pick expensive volume casts when a thin ray would do. This Skill provides decision tables, mandatory script patterns, and hard rules for reliable raycasts, shapecasts, and direct space state queries. ## Core Features & Use Cases - Query-Type Decision Table: Maps each need (hitscan, footing, explosions, picking, piercing) to the cheapest correct API, from RayCast nodes to intersect_ray, intersect_shape, intersect_point, and get_rest_info. - Mandatory Script Patterns: Ready-to-load GDScript recipes for direct space state raycasts, RID exclusion optimization, and ShapeCast ground detection, plus specialized scripts for FOV scanners, piercing projectiles, mouse picking, and buoyancy. - Safety Rules & Migration Notes: A NEVER-do list covering physics-step-only access, self-hit exclusion, and force_raycast_update timing, plus per-version Godot 4.x migration notes for query API changes. - Use Case: Implementing a hitscan weapon in a Godot 4 FPS: load the direct_space_state_raycast script, apply RID exclusion so the player never self-hits, and filter targets with collision masks instead of iterating results. ## Quick Start Ask the AI to implement a hitscan weapon raycast in Godot 4 using direct space state with proper self-exclusion and collision masks.

Frequently Asked Questions about godot-raycasting-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I raycast in Godot 4 without a RayCast node?▼

Use PhysicsDirectSpaceState3D.intersect_ray with a PhysicsRayQueryParameters3D built from origin and end points, called inside _physics_process. Set query.exclude to the caster's RID so the ray never hits its own character.

When should I use ShapeCast instead of RayCast in Godot?▼

Use ShapeCast when thin rays tunnel through walls or miss volume, such as footing detection, melee swings, or fast projectiles. Rays are cheaper, so default to RayCast unless you need volumetric detection.

How do I convert mouse position to a 3D ray in Godot?▼

Use Camera3D project_ray_origin and project_ray_normal with the viewport mouse position to build a world-space ray, then run intersect_ray against direct_space_state. Exclude the picking object's RID from the query.

Why does my Godot raycast hit the character that fires it?▼

A ray starting inside a character collides with that character's own shapes. Add the caster's RID to query.exclude, for example query.exclude = [get_rid()], and use collision masks to filter at the physics server level.

Why does my RayCast3D report stale results after moving it?▼

RayCast nodes update once per physics frame, so reading is_colliding immediately after teleporting returns old data. Call force_raycast_update() after moving the node before reading its collision state.

Can I access direct_space_state in _process instead of _physics_process?▼

No. The physics space can be locked or running on another thread during _process, making queries unsafe. Always access direct_space_state inside _physics_process or other physics-step callbacks.