【发布时间】:2011-11-14 13:38:17
【问题描述】:
我需要一个简单的 AI 脚本来让僵尸对象随机“走动”。我用谷歌搜索和搜索,但我能找到的只是数学函数“随机游走”上的东西。也许是相关的?
我正在使用我自己的 JavaScript 2D 引擎,我需要有类似的东西:
function update() {
//Move using available physics engine stuff:
// this.position, this.rotation, this.velocity, this.torque, this.acceleration
// this.torqueAcceleration, this.drag, this.torqueDrag
}
谢谢! :)
【问题讨论】:
-
使用随机函数来获得低百分比的机会改变方向(反转值)? - 请进一步解释你的问题是在这里。 -- 类似:
if (Math.floor(Math.random()*11) == 0) // 10% chance this.acceleration *= -1; -
如果你想要“真正”随机的东西,你必须使用
Math.random()。将其与距离和所有变量混合。我猜你说的不是人工智能? -
谢谢,我并不是说 AI(我已经构建了 AI),这就是我说简单的原因。只是想不出更好的表达方式 - 行为会更好
-
Mat Buckland 在他的书 Programming Game AI by Example 中解释了他称之为 Wander 的机器人行为。这使机器人四处游荡,而不仅仅是沿着笔直的路径行走。实现起来很简单。
标签: javascript artificial-intelligence 2d physics