Hello all! I’ve been looking through a tutorial and I can’t quite wrap my mind around the fact that the
enemy spatial does not turn in the player’s direction after being sensed. It just looks in one direction and does its running in one direction BUT the spatial does come after the player it just…looks in one direction and does all its controls in one direction such as: attacking, sprinting, and walking. Here’s the code for lookAt:
else if (sprinting)
{
if (!animChannel.getAnimationName().equals("run"))
{
animChannel.setAnim("run");
sprintStartTime = stage.getTime();
}
Vector3f move = target.getLocation().subtract(getLocation());
move.setY(0);
move.set(move.normalize());
control.applyCentralForce(move.mult(sprintForce));
Vector3f targetZero = target.getLocation();
targetZero.setY(getLocation().getY());
model.lookAt(targetZero, Vector3f.UNIT_Y);
if (stage.getTime() - sprintStartTime > sprintDuration)
{
sprinting = false;
animChannel.setAnim("walk");
}
It has something to do with these bits of code though:
Vector3f targetZero = target.getLocation();
targetZero.setY(getLocation().getY());
model.lookAt(targetZero, Vector3f.UNIT_Y);
if (toTarget.length() < attackStartDistance && stage.getTime() - attackTime > reAttackTime)
attacking = true;
if (toTarget.length() > sprintStartDistance && stage.getTime() - sprintStartTime > sprintRecharge)
sprinting = true;
}