Skip to content

Commit

Permalink
fix beam correction
Browse files Browse the repository at this point in the history
ReinWD committed Dec 12, 2019
1 parent ba65828 commit 760b581
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/java/think/rpgitems/power/impl/Beam.java
Original file line number Diff line number Diff line change
@@ -613,6 +613,7 @@ private void makeBounce(Block block, Vector towards, Vector step, Location lastL
}

double legacyBonus = 0;
double lastCorrected = 0;

private Vector homingCorrect(Vector towards, Location lastLocation, Entity target, Supplier<Entity> runnable) {
if (target == null) {
@@ -633,20 +634,26 @@ private Vector homingCorrect(Vector towards, Location lastLocation, Entity targe
Vector targetDirection = targetLocation.toVector().subtract(lastLocation.toVector());
float angle = clone.angle(targetDirection);
Vector crossProduct = clone.clone().getCrossProduct(targetDirection);
//make sure path is a circle
if (lastCorrected>0){
clone.rotateAroundAxis(crossProduct, lastCorrected);
}
//legacy
// double actualAng = (homing / 20) / (lengthInThisTick / lengthPerSpawn);
double actualAng = Math.asin(towards.length() / (homing));
if (angle > Math.toRadians(actualAng)) {
double actualAng = Math.asin(towards.length() / (2 * homing));
if (angle > actualAng) {
if (this.behavior.equals(Behavior.LEGACY_HOMING)) {
double lastActualAngle = Math.asin(towards.length() / (homing + legacyBonus));
legacyBonus += 0.5 * (lastActualAngle / (2*Math.PI));
actualAng = Math.asin(towards.length() / ((homing+legacyBonus)));
double lastActualAngle = Math.asin(towards.length() / (2*(homing + legacyBonus)));
legacyBonus += (lastActualAngle / (Math.PI));
actualAng = Math.asin(towards.length() / (2 * (homing+legacyBonus)));
}
// ↓a better way to rotate.
// will create a exact circle.
clone.rotateAroundAxis(crossProduct, actualAng);
lastCorrected = actualAng;
} else {
clone = targetDirection.normalize();
lastCorrected = 0;
}
return clone;
}

0 comments on commit 760b581

Please sign in to comment.