I have set up a ThreeJS Scene similar to the image provided.
The issue I'm facing is when trying to rotate Obj2
vertically around Obj1
, it ends up rotating around the Z
axis instead of the center point (0,0,0).
My goal is for Obj2
to orbit exclusively around Obj1
(positioned at (0,0,0)) without rotating around any other axis.
function configureObj2PositionHorizontally(angleInDegree) {
radianAngle = angleInDegree * oneDegreeInRadians;
obj2Mesh.position.x = distance * Math.cos(radianAngle);
obj2Mesh.position.z = distance * Math.sin(radianAngle);
console.log(radianAngle, distance);
}
function configureObj2PositionVertically(angleInDegree) {
radianAngle = angleInDegree * oneDegreeInRadians;
obj2Mesh.position.y = distance * Math.sin(radianAngle);
obj2Mesh.position.z = distance * Math.cos(radianAngle);
console.log(radianAngle, distance);
}
To address this behavior, how can I ensure that Obj2
orbits only around Obj1
? Any suggestions or solutions would be greatly appreciated!
You can view the JSFiddle sample code here: https://jsfiddle.net/janithsg/y8upn26v/25/