I am trying to make a simple airplane flying game. I’d like the users arrow-keys to rotate a plane around a 360 degree area where up and down is a relative Y-axis to the horizontal position of the airplane. The left and right arrows should just spin the plane around it’s z axis and allow for it to have a new Y-axis position. My question is – how can I rotate the airplane in a Y-axis that is relative to the new horizontal position?
I have a group called airplane and have done stuff like airplane.rotation.z (for left and right) and airplane.rotation.x (for up and down) – but the x axis isn’t along the new horizontal plane. I’ve also tried accessing the model/mesh within the group with airplane.children[1].matrix.rotation.x to see if this can change the relative Y-axis…This results in the same problem however. How do I find the relative Y-axis to it’s current horizontal position?
My code can be seen on jsfiddle here
Any help would be greatly appreciated.
Quite frankly, I am having a very difficult time understanding your question, but I think your question is: “How do I use the arrow keys to rotate an object around it’s internal z- or x-axis?”
A routine like this one will do that:
This routine uses quaternions for implementation. This is really no big deal — you just need to set:
Here is an updated fiddle: http://jsfiddle.net/Lc8gH/20/ .
EDIT: You can now use
Object3D.rotateOnAxis( axis, angle );three.js r.58