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.
Raycast(x1, y1, x2, y2, maxDistance, debugDraw, ignoreObject)
true, the ray is visually drawn in the scene (green or red depending on collision).
A hitInfo object, or null if nothing is hit:
{
hit: true,
object: referenceToObject,
x: 350,
y: 180,
distance: 220.5
}
// 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);
}
collision = true and trigger = false.light, darkness, and waypoint.