FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[FEATURE] Provide a more intuitive high-level raycast API in the Physics plugin · Issue #495 · EngineSquared/EngineSquared · GitHub

[FEATURE] Provide a more intuitive high-level raycast API in the Physics plugin #495

Description

Problem Statement

Performing a raycast requires reaching deep into Jolt internals — constructing raw JPH::RRayCast and JPH::RayCastResult objects and calling physicsSystem.GetNarrowPhaseQuery().CastRay(...). This is verbose, unintuitive, and leaks Jolt implementation details into user code. Flagged in ES-Factoria src/system/SetupClickOnPlanet.cpp:

// TODO: give a better API to do raycast, it's really not intuitive
bool hitFound = physicsSystem.GetNarrowPhaseQuery().CastRay(jphRay, hit);

Proposed Solution

Expose a high-level raycast API on Physics::Resource::PhysicsManager (or equivalent) that works entirely with engine-native types:

auto hit = physicsManager.Raycast(origin, direction, maxDistance);
if (hit) { /* hit->entity, hit->position, hit->fraction */ }

Alternative Solutions

  • Provide thin type-conversion helpers (ToJolt(vec), FromJolt((JPH)vec)) without wrapping the query — reduces boilerplate slightly but still exposes Jolt types.
  • Keep the raw Jolt API and document it well — no effort required but every project writes the same low-level code.

Use Cases

  • Use case 1: A click-to-select system performs a raycast in two lines using glm::vec3 without knowing about Jolt.
  • Use case 2: Any AI or gameplay system that needs line-of-sight checks benefits from the same clean API.

Impact

  • No performance implications (same underlying Jolt call).
  • New methods added to the Physics plugin's public API.
  • No breaking changes to existing direct Jolt usage.

Implementation Details (optional)

Additional Context

Spotted via a // TODO audit of the ES-Factoria demo project.

Related Issues

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestquality of lifeImprovements that enhance user or developer experience without adding new core features

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


Back | FazBrowse Home | New Git URL