I need help creating a game where an object (comet) can fly and rotate around another object (planet) in orbit. Currently, I have managed to make the comet move and turn towards the planet, but I am struggling to figure out how to make it start rotating around the planet's orbit once it reaches a certain distance.
this.mesh.translateZ(this.speed);
if (this.target.position.distanceTo(this.mesh.position) >= 100) {
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 = 0.01;
this.mesh.quaternion.rotateTowards(targetQuaternion, step);
}
} else {
// Need guidance on how to make the comet(this.mesh) fly around the planet(this.target)'s orbit
}