20 lines
947 B
Luau
20 lines
947 B
Luau
--!strict
|
|
export type Spec = {radius: number, height: number, sightHeight: number, exclusiveHeight: boolean?}
|
|
export type Reason = "Outside" | "Height" | "Blocked" | "Inside"
|
|
local Zones = {}
|
|
|
|
function Zones.reason(delta: Vector3, spec: Spec, blocked: boolean): Reason
|
|
if delta.X * delta.X + delta.Z * delta.Z > spec.radius * spec.radius then return "Outside" end
|
|
local height = math.abs(delta.Y)
|
|
if height > spec.height or (height == spec.height and spec.exclusiveHeight) then return "Height" end
|
|
return if blocked then "Blocked" else "Inside"
|
|
end
|
|
|
|
function Zones.classify(position: Vector3, center: Vector3, spec: Spec, geometry: RaycastParams): Reason
|
|
local candidate = Zones.reason(position - center, spec, false)
|
|
if candidate ~= "Inside" then return candidate end
|
|
local target = center + Vector3.yAxis * spec.sightHeight
|
|
return if workspace:Raycast(position, target - position, geometry) then "Blocked" else "Inside"
|
|
end
|
|
return Zones
|