Thanks for the help earlier, I'm currently fine-tuning the drone movement, and I was wondering how the param of Ship.giveCommand(..., param, ...) works. I've only been setting the param as null, but the API mentions
param - Generally a Vector2f with a "mouse" location. See ShipCommand.java for details., but as far as I can see ShipCommand.java doesn't have any comment on a mouse location. Does this mean that I can choose to make the e.g. accelerate command act in a certain direction instead of cardinally? The code below shows what I have. This is quite innacurate as the drones only move diagonally or straight, which causes them to overshoot, correct, then fly around amusingly. Thanks!
Spoiler
//MOVE TO TARGET LOCATION
float angleFromDroneToTargetLocation = VectorUtils.getAngleStrict(drone.getLocation(), movementTargetLocationOnShip);
float angleRelativeToDrone = MathUtils.getShortestRotation(drone.getFacing(), angleFromDroneToTargetLocation);
float distanceToTargetLocation = MathUtils.getDistance(drone.getLocation(), movementTargetLocationOnShip);
//do large movement if over distance threshold
if (distanceToTargetLocation >= roamRange) {
//accelerate forwards or backwards
if (90f > angleRelativeToDrone && angleRelativeToDrone > -90f) { //between 90 and -90 is an acute angle therefore in front
drone.giveCommand(ShipCommand.ACCELERATE, null, 0);
drone.giveCommand(ShipCommand.ACCELERATE, null, 0);
drone.giveCommand(ShipCommand.ACCELERATE, null, 0);
} else { //falls between 90 to 180 or -90 to -180, which should be obtuse and thus relatively behind
drone.giveCommand(ShipCommand.ACCELERATE_BACKWARDS, null, 0);
}
//strafe left or right
if (180f > angleRelativeToDrone && angleRelativeToDrone > 0f) { //between 0 and 180 (i.e. left)
drone.giveCommand(ShipCommand.STRAFE_LEFT, null, 0);
} else { //between 0 and -180 (i.e. right)
drone.giveCommand(ShipCommand.STRAFE_RIGHT, null, 0);
}
} else {
snapTo(ship, 0.1f, drone, movementTargetLocationOnShip);
}
//some fine tuning and deceleration
if (distanceToTargetLocation <= roamRange * 2f) {
drone.giveCommand(ShipCommand.DECELERATE, null, 0);
if (tracker.intervalElapsed()) {
//decelerate if close to target location or attempt to reverse thrust
if (distanceToTargetLocation <= roamRange) {
drone.giveCommand(ShipCommand.DECELERATE, null, 0);
if (drone.getEngineController().isStrafingRight()) {
drone.giveCommand(ShipCommand.STRAFE_LEFT, null, 0);
}
if (drone.getEngineController().isStrafingLeft()) {
drone.giveCommand(ShipCommand.STRAFE_RIGHT, null, 0);
}
if (drone.getEngineController().isAccelerating()) {
drone.giveCommand(ShipCommand.ACCELERATE_BACKWARDS, null, 0);
}
if (drone.getEngineController().isAcceleratingBackwards()) {
drone.giveCommand(ShipCommand.ACCELERATE, null, 0);
}
}
}
}