Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Design and review game spatial query code for raycasts, picking, collision predicates, containment tests, orientation tests, and point/line/plane distances. Use when implementing or debugging ray-triangle hits, point-in-triangle checks, barycentric constraints, signed distance tests, or geometry predicates.
.claude/skills/hashgraph-online-game-spatial-queries/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-03 | ✗→✓ | ▲ Improved | 21% | 0% |
| case-10 | ✓→✓ | = Same ✓ | 37% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 13% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 15% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 20% | 0% |
Use this skill to turn game picking, collision, containment, and distance questions into small geometric systems with explicit constraints and failure cases.
Primary source: Geometry for Programmers by Oleksandr Kaleniuk (https://www.manning.com/books/geometry-for-programmers), transformed and paraphrased, especially chapters 3, 4, and 9. Additional source: "Fast, Minimum Storage Ray-Triangle Intersection" by Tomas Moller and Ben Trumbore (https://dl.acm.org/doi/10.1145/1198555.1198746).
closest distance, signed side, intersection point, or parameter value.
and object-local bases often reduce the query to bounds checks.
code instead of burying them in one large expression.
inclusive boundary, exclusive boundary, or conservative fallback.
Model the ray as R = P + t*d with t >= 0. Model triangle points as S = A + u*AB + v*AC with u >= 0, v >= 0, and u + v <= 1.
Solve R = S, then:
t < 0.u < 0, v < 0, or u + v > 1.t, barycentric-like parameters u and v, and the hitpoint when needed.
Prefer one of these approaches:
0 <= u, 0 <= v,u + v <= 1.
Decide whether points on edges count as inside. Tests must cover both the chosen edge policy and reversed triangle winding.
Build a plane normal from two nonparallel edges. Dot the normalized normal with the vector from any plane point to the query point. Keep the sign when side matters; take absolute value only for unsigned distance.
Project onto the segment direction, clamp the parameter to [0, 1], then measure distance to the clamped point. Reject or special-case zero-length segments before normalization.
or fallback query.
wrong across different world scales.
checks; collision separation often wants conservative checks.
normal, barycentric weights, or rejection reason.
parallel case, degenerate case, and large/small scale case.
bool from a query that later needs hit distance or normal.Other measured skills in the registry, with their headline benchmark lift.