Artificial intelligence 蜘蛛模型碰撞响应

Artificial intelligence 蜘蛛模型碰撞响应,artificial-intelligence,processing,vector-graphics,Artificial Intelligence,Processing,Vector Graphics,我正在使用OpenProcessing中的演示程序,并尝试为我生成的spider使用一个简单的规避AI。目标是让AI蜘蛛避开玩家控制的蜘蛛。我的代码: float distance = sqrt((c2.currentX - creature.currentX)*(c2.currentX - creature.currentX)+(c2.currentY-creature.currentY)*(c2.currentY-creature.currentY)); if (distanc

我正在使用OpenProcessing中的演示程序,并尝试为我生成的spider使用一个简单的规避AI。目标是让AI蜘蛛避开玩家控制的蜘蛛。我的代码:

float distance = sqrt((c2.currentX - creature.currentX)*(c2.currentX - creature.currentX)+(c2.currentY-creature.currentY)*(c2.currentY-creature.currentY));      

if (distance < c2.radius){
    c2.heading = atan(c2.heading);
    if(millis() - time >= wait){
        time = millis();
    }
}
float distance=sqrt((c2.currentX-生物.currentX)*(c2.currentX-生物.currentX)+(c2.currentY生物.currentY)*(c2.currentY生物.currentY));
if(距离小于c2.半径){
c2.航向=atan(c2.航向);
如果(毫秒()-时间>=等待){
时间=毫秒();
}
}

这位于我更新的draw()中,我收到了AI的响应,但响应要么是AI静止不动,要么是从屏幕上消失。任何帮助都将不胜感激。

如果你想让AI蜘蛛直接离开玩家,那么这样计算你的航向可能会更好(尽管在没有看到所有代码的情况下很难确定):

它所做的是计算从
生物
c2
的角度,并将其用作航向。结果应该是
c2
将直接从
生物
移动

(我假设
c2
就是这里的AI蜘蛛!)


作为旁注,在
atan
中传递一个角度可能不会给您带来任何有用的东西。它的设计目的是接受三角比作为参数<代码>atan2非常相似,但它通常更有用,因为它为您做了更多的工作。

感谢您的帮助,各位,我将努力实施这些建议。
c2.heading = atan2(c2.currentY - creature.currentY, c2.currentX - creature.currentX);