官术网_书友最值得收藏!

Avoiding blocks and agents

Modifying the SeekingAgent.lua script by adding the weighted sum of the ForceToAvoidAgents and ForceToAvoidObjects functions allows for the seeking agent to avoid potential collisions. When running the sandbox, try shooting boxes in the path of the agent and watch it navigate around the boxes:

SeekingAgent.lua

function Agent_Update(agent, deltaTimeInMillis)
    local destination = agent:GetTarget();
    local deltaTimeInSeconds = deltaTimeInMillis / 1000;
    local avoidAgentForce = agent:ForceToAvoidAgents(1.5);
    local avoidObjectForce = agent:ForceToAvoidObjects(1.5);
    local seekForce = agent:ForceToPosition(destination);
    local targetRadius = agent:GetTargetRadius();
    local radius = agent:GetRadius();
    local position = agent:GetPosition();
    local avoidanceMultiplier = 3;

    -- Sum all forces and apply higher priority to avoidance 
    -- forces.
    local steeringForces =
        seekForce +
        avoidAgentForce * avoidanceMultiplier +
        avoidObjectForce * avoidanceMultiplier;

    AgentUtilities_ApplyForce(
        agent, steeringForces, deltaTimeInSeconds);

    ...

end

Sandbox.lua:

require "DebugUtilities";

function Sandbox_Update(sandbox, deltaTimeInMillis)
    -- Grab all Sandbox objects, not including agents.
    local objects = Sandbox.GetObjects(sandbox);
    
    -- Draw debug bounding sphere representations for objects with 
    -- mass.
    DebugUtilities_DrawDynamicBoundingSpheres(objects); 
end

Now when we run the sandbox, we can shoot boxes at our seeking agent and watch it steer around each object.

Avoiding obstacles using avoidance

主站蜘蛛池模板: 青河县| 舞钢市| 玉溪市| 黎平县| 奇台县| 达尔| 玛沁县| 广州市| 乐平市| 英德市| 卫辉市| 克什克腾旗| 利辛县| 鸡西市| 黄大仙区| 隆德县| 新田县| 邢台市| 东安县| 岳池县| 浑源县| 松溪县| 昂仁县| 老河口市| 定襄县| 新田县| 涿州市| 揭西县| 黎川县| 女性| 无锡市| 潍坊市| 绥宁县| 南木林县| 安吉县| 彭泽县| 象山县| 维西| 阿鲁科尔沁旗| 科技| 田阳县|