我需要一个简单的人工智能脚本,让僵尸对象‘走’周围随机。我用谷歌搜索了又搜索,但我能找到的只是数学函数'Random Walk‘的内容。也许这是相关的?
我使用的是我自己的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
}谢谢!:)
发布于 2011-11-14 21:47:55
2年前,我确实在C# XNA中做过类似的脚本。
逻辑很简单。让我们来讨论一下在伪代码中遍历僵尸的逻辑:
以下是僵尸的可行走空间/平台:
x = 0 ___________________________ x = 100X=0 _____________________<_____ x= 100 x=0 _______>___________________ x= 100
这应该可以帮助你创建你的脚本,让所有的僵尸在地图上漫无目的地漫游。您可以更改我在伪代码中编写的值,以适合您的游戏。
发布于 2011-11-14 21:59:56
我希望你知道这和具体的编码一点关系都没有。这纯粹是逻辑。AI (人工智能)逻辑更具体地说。
你的僵尸产卵,下一步呢?您想要分配一个行为。写下一些不同的行为。
如果僵尸站着不动,什么也不做。
如果僵尸正在行走,则选择随机速度和随机方向。
每隔x秒选择一个新的行为。
我会怎么做:
// pick behavior between 0 and 5 seconds
var behaviorTimeout = setTimeout(randomBehavior, Math.round(Math.random() * 5000);
function randomBehavior() {
// set random values
this.rotation = Math.random() * 360; // assuming its in degrees
this.velocity = Math.random() * MAX_ZOMBIE_SPEED;
// run this again in something between 0 and 5 seconds
behaviorTimeout = setTimeout(randomBehavior, Math.round(Math.random() * 5000);
}这显然只适用于步行。你需要另一个随机数来决定它是应该行走还是停下来。
这是人们能想到的最基本的AI逻辑。如果你不再谈论僵尸,但真正有思想的生物理解和创造人工智能将变得更加困难。
https://stackoverflow.com/questions/8122402
复制相似问题