you probably noticed me asking quite a few questions related to my project so thank you in advance for all the support.
My project consists of a planet earth and moon that rotate around the sun. (They aren't specifically rotating around the sun, it's more just around the 0,0 axis where the sun happens to be).
I initially created my geometries and then added them into the scene and then into the orbit group as follows
var orbitGroup = new THREE.Object3D();
scene.add(orbitGroup);
scene.add(planetEarth);
orbitGroup.add(planetEarth);
scene.add(planetMoon);
orbitGroup.add(planetMoon);
I then declared the rotation within the render function as follows
planetEarth.add( planetMoon );
planetEarth.add(rocketGroup);
// call the render function
var angle = 0;
render();
function render() {
stats.update();
// rotate the orbit group
angle += 0.002;
angle += 0.002 * controls.EarthRotationSpeed;
planetEarth.rotation.y += controls.EarthRotationSpeed;
planetMoon.rotation.y += controls.MoonRotationSpeed;
angle+= 0.01 * controls.SunRotationSpeed;
planetSun.rotation.y += controls.SunRotationSpeed;
// rotate the orbit group
angle += 0.02;
orbitGroup.rotation.y = -angle / 10;
littleOrbitGroup.rotation.x = -angle;
// render using requestAnimationFrame
requestAnimationFrame(render);
renderer.render(scene, camera);
}
As you can tell, the moon and the earth are both orbiting around the sun instead of the moon rotating the earth while it rotates the sun. Is there a way I can declare the specific point or object that it should orbit and also make it orbit it at whatever axis I want rather than specifically on the y axis?
----------------EDIT-----------------
function createMesh(geom) {
var loader = new THREE.TextureLoader();
var planetTexture = loader.load("../assets/textures/planets/Earth.png");
var normalTexture = loader.load("../assets/textures/planets/EarthNormal.png");
var planetMaterial = new THREE.MeshPhongMaterial({map: planetTexture, bumpMap: normalTexture});
// create a multimaterial
var mesh = THREE.SceneUtils.createMultiMaterialObject(geom, [planetMaterial]);
return mesh;
}