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

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

主站蜘蛛池模板: 景德镇市| 武宣县| 永吉县| 汨罗市| 科技| 奈曼旗| 玉门市| 邵阳市| 赤城县| 汝阳县| 麻阳| 扬中市| 德格县| 儋州市| 邳州市| 酒泉市| 沐川县| 莱州市| 朝阳区| 恩施市| 长春市| 四川省| 航空| 佛坪县| 桂林市| 印江| 黑河市| 拜泉县| 襄垣县| 平陆县| 屯门区| 维西| 陕西省| 宝鸡市| 潮州市| 哈巴河县| 大关县| 津南区| 太原市| 横峰县| 县级市|