Commit 07e7e336 by Jonathan Thomas

Adding 30 degree randomness into LEAD behavior targeting.

parent 95c8aba4
Pipeline #12713 passed with stages
in 2 minutes 21 seconds
...@@ -111,7 +111,7 @@ public class LeadPlayerGoal extends PlayerBaseGoal { ...@@ -111,7 +111,7 @@ public class LeadPlayerGoal extends PlayerBaseGoal {
currentSpeed = MathHelper.stepTowards((float)currentSpeed, (float)this.speed, (float) (0.005 * (this.speed / Math.max(currentSpeed, 0.1)))); currentSpeed = MathHelper.stepTowards((float)currentSpeed, (float)this.speed, (float) (0.005 * (this.speed / Math.max(currentSpeed, 0.1))));
// Apply movement with the adjusted speed towards the target // Apply movement with the adjusted speed towards the target
Vec3d newVelocity = new Vec3d(moveDirection.x * currentSpeed, this.entity.getVelocity().y, moveDirection.z * currentSpeed); Vec3d newVelocity = new Vec3d(moveDirection.x * currentSpeed, moveDirection.y * currentSpeed, moveDirection.z * currentSpeed);
this.entity.setVelocity(newVelocity); this.entity.setVelocity(newVelocity);
this.entity.velocityModified = true; this.entity.velocityModified = true;
...@@ -123,7 +123,7 @@ public class LeadPlayerGoal extends PlayerBaseGoal { ...@@ -123,7 +123,7 @@ public class LeadPlayerGoal extends PlayerBaseGoal {
// Increment waypoint // Increment waypoint
currentWaypoint++; currentWaypoint++;
LOGGER.info("Waypoint " + currentWaypoint + " / " + this.totalWaypoints); LOGGER.info("Waypoint " + currentWaypoint + " / " + this.totalWaypoints);
this.currentTarget = RandomTargetFinder.findRandomTarget(this.entity, 0, 24, 36); this.currentTarget = RandomTargetFinder.findRandomTarget(this.entity, 30, 24, 36);
if (this.currentTarget != null) { if (this.currentTarget != null) {
emitParticleAt(this.currentTarget, ParticleTypes.FLAME); emitParticleAt(this.currentTarget, ParticleTypes.FLAME);
emitParticlesAlongRaycast(this.entity.getPos(), this.currentTarget, ParticleTypes.CLOUD, 0.5); emitParticlesAlongRaycast(this.entity.getPos(), this.currentTarget, ParticleTypes.CLOUD, 0.5);
......
...@@ -52,15 +52,21 @@ public class RandomTargetFinder { ...@@ -52,15 +52,21 @@ public class RandomTargetFinder {
} }
private static Vec3d getConstrainedDirection(Vec3d initialDirection, double maxAngleOffset) { private static Vec3d getConstrainedDirection(Vec3d initialDirection, double maxAngleOffset) {
double currentAngle = Math.atan2(initialDirection.z, initialDirection.x); double randomYawAngleOffset = (random.nextDouble() * Math.toRadians(maxAngleOffset)) - Math.toRadians(maxAngleOffset / 2);
double randomPitchAngleOffset = (random.nextDouble() * Math.toRadians(maxAngleOffset)) - Math.toRadians(maxAngleOffset / 2);
double randomHorizontalAngleOffset = (random.nextDouble() * Math.toRadians(maxAngleOffset)) - Math.toRadians(maxAngleOffset / 2); // Apply the yaw rotation (around the Y axis)
double constrainedAngle = currentAngle + randomHorizontalAngleOffset; double cosYaw = Math.cos(randomYawAngleOffset);
double sinYaw = Math.sin(randomYawAngleOffset);
double xYaw = initialDirection.x * cosYaw - initialDirection.z * sinYaw;
double zYaw = initialDirection.x * sinYaw + initialDirection.z * cosYaw;
double x = Math.cos(constrainedAngle); // Apply the pitch rotation (around the X axis)
double z = Math.sin(constrainedAngle); double cosPitch = Math.cos(randomPitchAngleOffset);
double sinPitch = Math.sin(randomPitchAngleOffset);
return new Vec3d(x, initialDirection.y, z).normalize(); double yPitch = initialDirection.y * cosPitch - zYaw * sinPitch;
double zPitch = zYaw * cosPitch + initialDirection.y * sinPitch;
return new Vec3d(xYaw, yPitch, zPitch).normalize();
} }
private static Vec3d getTargetInDirection(MobEntity entity, Vec3d direction, double minDistance, double maxDistance) { private static Vec3d getTargetInDirection(MobEntity entity, Vec3d direction, double minDistance, double maxDistance) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment