Raycast#
Defined in Core.hpp. World-space line tracing for line-of-sight checks and custom traces.
The raycast system uses the game's native navmesh BVH for fast, accurate world geometry intersection. Player collision shapes are automatically excluded.
IsRaycastReady#
Returns true if the native raycast system is initialized and ready to accept traces. Always check this before calling Raycast() or IsPointVisible().
Note
The raycast context is initialized once per match when the navmesh data becomes available. It is not available in menus or during loading screens.
Raycast#
Traces a line from from to to through world geometry and returns detailed hit information.
| Parameter | Type | Description |
|---|---|---|
from |
const Vector3& |
Ray start position (world space) |
to |
const Vector3& |
Ray end position (world space) |
| Returns | Description |
|---|---|
RaycastResult |
Hit position, fraction, and hit flag |
Vector3 eye = LocalPlayer().GetBonePos(Bone::Head);
Vector3 target = enemy.GetBonePos(Bone::Head);
RaycastResult hit = Raycast(eye, target);
if (hit.IsHit())
{
// Ray was blocked by world geometry
Vector2 screen;
if (WorldToScreen(hit.hitPos, screen))
Draw::CircleFilled(screen, 4.f, Color::Red());
}
Warning
Each raycast call has a small performance cost. Avoid calling more than ~20 raycasts per frame. For simple visibility checks, prefer IsPointVisible().
IsPointVisible#
Quick line-of-sight check between two world points. Returns true if the line is unobstructed (or nearly so — fraction > 0.98).
| Parameter | Type | Description |
|---|---|---|
from |
const Vector3& |
Start position (world space) |
to |
const Vector3& |
End position (world space) |
| Returns | Description |
|---|---|
true |
Line of sight is clear |
false |
World geometry blocks the line |
Vector3 eye = LocalPlayer().GetBonePos(Bone::Head);
for (Entity player : Players())
{
if (!player.IsAlive() || !player.IsEnemy()) continue;
if (IsPointVisible(eye, player.GetBonePos(Bone::Head)))
Draw::Text(WorldToScreen(player.GetPosition()), Color::Green(), "VISIBLE");
}
RaycastResult#
struct RaycastResult
{
Vector3 hitPos;
float fraction; // 0.0 = hit at start, 1.0 = no hit
int32_t hit; // 1 = hit geometry, 0 = clear
bool IsHit() const;
bool IsVisible() const;
};
Returned by Raycast().
| Field | Type | Description |
|---|---|---|
hitPos |
Vector3 |
World-space position where the ray hit geometry |
fraction |
float |
How far along the ray the hit occurred (0.0 = start, 1.0 = end/no hit) |
hit |
int32_t |
1 if geometry was hit, 0 if clear |
| Method | Returns | Description |
|---|---|---|
IsHit() |
bool |
true if the ray hit world geometry |
IsVisible() |
bool |
true if the ray is clear (no hit, or fraction > 0.98) |