I am working on creating a spaceship-like object with controls, and I have learned that I need to use quaternions to achieve this. To start, I am attempting to make a cube rotate to the left when the A key is pressed. Here is the code I have written for this:
if(controls.pressingA === true)
{
//var pLocal = new THREE.Vector3( 0, 0, -1 );
//var pWorld = pLocal.applyMatrix4( me.matrixWorld );
//var dir = pWorld.sub( me.position ).normalize();
var dir = me.getWorldDirection();
var quaternion = new THREE.Quaternion().setFromAxisAngle( dir, 0.05 );
me.rotation.setFromQuaternion( quaternion );
}
Based on my understanding of this code, the me.getWorldDirection()
function retrieves the axis that the object is facing. Then, I create a quaternion based on this axis and rotate the object by 0.05 degrees in radians. However, the issue I am facing is that it sets the rotation of my object rather than increasing it. How can I adjust the code to increase the rotation instead of merely setting it?