Game Development Reference
In-Depth Information
local rayVector = Vector.Normalize(
centroid - rayCastPosition);
local dotProduct = Vector.DotProduct(rayVector,
forward);
-- Only check visibility within a 45 degree tolerance
local cos45Degrees = 0.707;
if (dotProduct >= cos45Degrees) then
local raycast = Sandbox.RayCastToObject(
sandbox, rayCastPosition, centroid);
-- Check if the ray hit the intended agent.
if ((raycast.result and
Agent.IsAgent(raycast.object) and
raycast.object:GetId() == agent:GetId()) or
not raycast.result) then
if (debug) then
Core.DrawLine(
rayCastPosition,
centroid,
DebugUtilities.Green);
end
local visibleAgent = {};
visibleAgent["agent"] = agent;
visibleAgent["seenAt"] = centroid;
visibleAgent["lastSeen"] = sandboxTime;
return visibleAgent;
else
if (debug) then
Core.DrawLine(
rayCastPosition,
centroid,
DebugUtilities.Red);
end
end
Search WWH ::




Custom Search