Game Development Reference
In-Depth Information
Creating a visual representation
Now that you have an agent running within the sandbox, we need to create a visual repres-
entation so that we can see the agent. This time, we use the Core. CreateCapsule
function to procedurally generate a capsule mesh and attach the mesh to the agent itself.
Passing the agent to Core.CreateCapsule will attach the Ogre mesh directly to the
agent and automatically update the position and rotation of the capsule as the agent moves.
We only need to create a visual representation compared to a Sandbox.CreateObject
object, as agents are already simulated within the physics simulation with a capsule repres-
entation:
Create the Lua file as follows:
src/my_sandbox/script/AgentUtilities.lua
AgentUtilities.lua :
function AgentUtilities_CreateAgentRepresentation(
agent, height, radius)
-- Capsule height and radius in meters.
local capsule = Core.CreateCapsule(agent, height,
radius);
Core.SetMaterial(capsule, "Ground2");
end
Agent.lua :
function Agent_Initialize(agent)
AgentUtilities_CreateAgentRepresentation(
agent, agent:GetHeight(), agent:GetRadius());
end
Running the sandbox now will show our agent's visual representation, a capsule using the
same Ogre Ground2 material.
Search WWH ::




Custom Search