Skip to content

Commit

Permalink
fix: guntower ai angle and rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Sep 21, 2023
1 parent 91a008c commit 4c7e428
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@ public void tick(float delta) {
.cpy()
.sub(this.target.getTranslation().add(0, this.target.getAverageTurretPosition().y, 0))
.nor();
final float angle = this.target.getLookDirection().dot(closestDir);

if (MathUtils.isEqual(angle, 1f, 0.3f)) {
this.target.fire();
}

// final Vector3 newDir = this.target.getLookDirection().slerp(closestDir, this.turnSpeed * delta);
Vector3 newDir = closestDir.cpy();
final Vector3 newDir = this.target.getLookDirection().slerp(closestDir, delta);
// Vector3 newDir = closestDir.cpy();
newDir.rotateRad(Vector3.X, MathUtils.HALF_PI);

final float polar = MathUtilsW.getSphericalPolar(newDir.z);
final float azimuth = MathUtilsW.getSphericalAzimuth(newDir.x, newDir.y);

this.target.setPolarAngle(1 - (polar / MathUtils.PI));
this.target.setAzimuth(1 - (azimuth / MathUtils.PI2));

final float angle = this.target.getLookDirection().dot(closestDir);

if (MathUtils.isEqual(angle, 1f, 0.1f)) {
this.target.fire();
}
}
}

0 comments on commit 4c7e428

Please sign in to comment.