Game Development Reference
In-Depth Information
Detecting other visible agents
Detecting other visible agents can essentially be broken down into three sequential parts.
To determine the starting position of our raycasts, we use the b_Head1 bone of our agent.
This gives us a relative approximation for our agent's eye position and orientation.
Next, we determine whether the ray we want to cast to another agent's position falls within
a 45 degree cone from the soldier model's b_Head1 bone position and orientation. This is
easily accomplished with a dot product check between our possible ray used for ray casting
and a vector to the other agent.
If the agent is within our viewing range, we can directly cast a ray to the centroid (which is
the center of mass) of the other agent to determine whether our agent can actually see the
other agent. There are a few possibilities: the ray penetrates an object that isn't the agent we
want to see, the ray penetrates the agent we are trying to view, or the ray penetrates noth-
ing. While the last case doesn't seem like it should happen, it can happen if the agent's body
isn't where our centroid is expecting it to be; usually, this means that the agent is already
dead and the body is lower on the floor than we're expecting:
AgentSenses.lua :
require "DebugUtilities"
function AgentSenses_CanSeeAgent(userData, agent, debug)
local sandbox = userData.agent:GetSandbox();
local position = Animation.GetBonePosition(
userData.soldier, "b_Head1");
local rotation = Animation.GetBoneRotation(
userData.soldier, "b_Head1");
-- The negative forward vector is used here, but is
model
-- specific.
local forward = Vector.Rotate(Vector.new(0, 0, -1),
rotation);
local rayCastPosition = position + forward / 2;
local sandboxTime = Sandbox.GetTimeInMillis(sandbox);
local centroid = agent:GetPosition();
Search WWH ::




Custom Search