It is possible to have objects move alongside their axis.
Translate x/y/z for each respective axis.
And if I want to move on all of them at the same time, I can use TranslateOnAxis.
But those just move the object by quantity in each axis.
How do I move, say, into the following direction:
x rotation: 0.1 radians.
y rotation: 0.2 radians.
So I can move the object into a vector determined angle, relative to where it is heading.
Rather than just pixel quantities on xyz.
Your terminology is mathematically wrong. Two rotation values do not define a direction. A complete Euler angle definition defines an orientation in 3D space. If you want to transform a 3D object from one orientation to another one, use Object3D.lookAt(). Or Quaternion.rotateTowards() if you want to animate the transition.
I dont’t need the transition to be animated, as I am calling the function again and again via requestanimationframe.
I looked up 3js lookat, here: https://threejs.org/docs/#api/en/core/Object3D.lookAt
It says that it rotates the object in the given direction. But I absolutely do not want it to rotate in this given direction. I just want it to move a bit in this direction.
I looked up quaternions.
Wasn’t helpful.
How should I use quaternions and lookat to achieve this?
Then forget Object3D.lookAt(). If say you start with an Euler angle e you can try this:
const q = new THREE.Quaternion().setFromEuler( e );
const v = new THREE.Vector3( 0, 0, 1 ).applyQuaternion( q );
const offset = 1; // world units
object.position.add( v.multiplyScalar( offset ) );
However, this code is not much different from Object3D.translateOnAxis().
I get error:
THREE.Quaternion.setFromEuler is not a constructor
So I can’t run this code.
It’s also very confusing.
Because euler is apparently an angle.
Which is good.
But then, that vector is also representing an angle.
LIke, which one is the angle?
Also, if this is not much different from translateOnAxis.
Which method is better?
Which one should we go for?