🎯 Raycast

What is it?

Raycast() allows you to cast a ray between two points in the world to detect collisions with solid objects. It is useful for enemy vision, shooting, sensors, or physical interactions.

📖 Syntax

Raycast(x1, y1, x2, y2, maxDistance, debugDraw, ignoreObject)

📍 Parameters

📦 Returns

A hitInfo object, or null if nothing is hit:

{
  hit: true,
  object: referenceToObject,
  x: 350,
  y: 180,
  distance: 220.5
}

✅ Example

// Cast a ray from an enemy toward the player
const hit = Raycast(enemy.x, enemy.y, player.x, player.y, 800, true, enemy);

if (hit) {
  console.log("Hit:", hit.object.name);
}

📌 Notes

- Only detects active objects with collision = true and trigger = false.
- Ignores objects of type light, darkness, and waypoint.
- You can cast multiple rays in the same frame without impacting performance.