I’ve been stuck on trying to get a Player ship to orbit around a moving enemy ship (and vice versa).
The easiest way to visualize what I’m trying to achieve is exactly the same way EVE Online approaches a target, and then slowly rotates around a given radius.
I could only make the fleet turn and fly toward the enemy fleet, but it is necessary that when a certain distance is reached, the fleet starts to rotate around enemys fleet orbit.
this.mesh.translateZ(this.speed);
if (this.target.position.distanceTo(this.mesh.position) >= 100 /* distance */) {
let targetQuaternion = new THREE.Quaternion();
let rotationMatrix = new THREE.Matrix4();
rotationMatrix.lookAt(this.mesh.position, this.target.position, this.mesh.up);
targetQuaternion.setFromRotationMatrix(rotationMatrix);
if (!this.mesh.quaternion.equals(targetQuaternion)) {
let step = velocity;
this.mesh.quaternion.rotateTowards(targetQuaternion, step);
}
} else {
//how to make a fleet (this.mesh) fly around the orbit of enemy fleet (this.target)?
}
ps. grouping of objects is not suitable, because these are separate game objects with their speed and other parameters.