- Learning Game AI Programming with Lua
- David Young
- 171字
- 2021-08-05 17:02:15
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
推薦閱讀
- Building Computer Vision Projects with OpenCV 4 and C++
- 數據之巔:數據的本質與未來
- iOS and OS X Network Programming Cookbook
- 3D計算機視覺:原理、算法及應用
- 數據架構與商業智能
- 數字媒體交互設計(初級):Web產品交互設計方法與案例
- Proxmox VE超融合集群實踐真傳
- MATLAB Graphics and Data Visualization Cookbook
- 大數據時代系列(套裝9冊)
- 智能與數據重構世界
- 企業級大數據項目實戰:用戶搜索行為分析系統從0到1
- 數據中臺實戰:手把手教你搭建數據中臺
- Delphi High Performance
- NoSQL數據庫原理(第2版·微課版)
- 社交網站的數據挖掘與分析(原書第2版)