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

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

主站蜘蛛池模板: 元氏县| 兴隆县| 津市市| 乐东| 米易县| 蓬安县| 大方县| 星子县| 玉溪市| 新宁县| 昭通市| 杭锦旗| 云和县| 青海省| 达州市| 香格里拉县| 勃利县| 涟源市| 黎平县| 儋州市| 青龙| 彝良县| 浦北县| 曲沃县| 永康市| 大渡口区| 武城县| 吉隆县| 大同县| 西乡县| 林周县| 阿拉尔市| 嘉义县| 汶上县| 广东省| 萨嘎县| 丹江口市| 宣城市| 久治县| 阿坝县| 鹰潭市|