AI寻求行为问题

时间:2014-04-25 20:06:17

标签: java artificial-intelligence game-engine game-physics

@Override
public void update() {
    float c = TIME_DELTA * 10;
    Vector desiredVelocity = Vector.subtract(target, pos()).normalize().multiply(c);
    Vector steering = Vector.subtract(desiredVelocity, velocity);
    steering.truncate(0.4f);
    steering.multiply(0.0956023f); //divide by mass
    velocity.add(steering);
    velocity.truncate(3f);
    setX(getX() + velocity.x);
    setY(getY() + velocity.y);
}

我尝试按照本指南http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-seek--gamedev-849进行操作,但实施时遇到问题。当我运行代码时,精灵行为奇怪,x和y最终变成NaN。我已经尝试了查找它并且我已经在试图让代码工作了几天,但是我没有成功。谁能告诉我我做错了什么?

0 个答案:

没有答案