Currently, I am working on developing a simple Three.js application. One of the main objectives is to synchronize the moon's movements with the Earth's. Although I have a method that allows the moon to rotate in a circular motion statically, the rotation pattern gets disrupted when you move around the planet, causing the moon's path to become elliptical until it realigns after a few rotations.
The function responsible for this rotation can be seen below:
rotateMoon = function(rotSpeed) {
var x = moon.position.x,
y = moon.position.y,
z = moon.position.z;
moon.position.x = x * Math.cos(rotSpeed) + z * Math.sin(rotSpeed);
moon.position.z = z * Math.cos(rotSpeed) - x * Math.sin(rotSpeed);
}
My objective is to connect the moon's movement to the Earth's, essentially making it dependent on the Earth's rotation. How can I achieve this seamless synchronization?