I am facing a challenge in moving an object upwards in relation to its current direction. I am working with a CubeGeometry that has a specific height, and my goal is to place an object at the top of it and have it rotate along with the cube. Simply adding the new object to the cube won't suffice because I need to access the rotation of this object (which will be rotated subsequently) and its parent object. To elaborate, if you are looking upwards, "up" would be sideways. I attempted to determine the direction an object is facing using .getWorldDirection() and rotating it with .applyAxisAngle(), but for some reason, this approach is not yielding the desired outcome. Here is my current code:
tmpObj.position.set(cube.position.x, cube.position.y, cube.position.z); // placed at the cube's position
var gwd = cube.getWorldDirection().applyAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI*-0.5); // applying applyAxisAngle to ensure correct direction
gwd.multiplyScalar(2.5); // cube's height
tmpObj.position.add(gwd);
As a result, the cube (tmpObj
) moves in the opposite direction when the cube
is rotated.
Just to clarify, there are additional objects (tmpObj
and cube
with different names) that will eventually face each other to determine their relative positions.