So I'm new to working with a 3D space and not sure how to fix my problem, I basically have a turret that rotates along its Z axis, and pitches along it's Y but after rotating 180 on the Z axis the turret points down as I completely understand despite being unexpected.

I have a fiddle with what I'm working on here https://jsfiddle.net/2v4ezmaz/2/

So the question is, how do I make it rotate like it does in blender where the barrel end stays pointing up while rotating the z? After lots of reading it's all to do with cross vectors since the .rotation property is euler angles which I think is my problem. I need to use quaternions but I can't logically see what needs to happen.

My brain is thinking of it as needing to reset the rotation back to its default then apply Z rotation and apply the Y rotation, but that can't be right.

After reading http://blog.wolfire.com/2010/07/Linear-algebra-for-game-developers-part-4 I'm sure my answer is there somewhere but I cant think what the code needs to be to do what i want.

Any pointers would be super helpful since my brain is fried reading/trying vector and matrix rotations.

  • \$\begingroup\$ That fiddle displays some stuff that doesn't seem to be related to your question. I can't see where on the ship this problematic turret is supposed to be. \$\endgroup\$ – user253751 Sep 26 '16 at 23:56
  • \$\begingroup\$ Strange, should be the left most turret from the default view. I know theres texture errors going on but shows up fine for me with chrome :/ \$\endgroup\$ – Julian Sep 27 '16 at 0:05
  • \$\begingroup\$ No, I mean that I can't tell where the problematic turret is because you didn't tell me where to look. \$\endgroup\$ – user253751 Sep 27 '16 at 0:07

It appears the two rotations are being applied in the wrong order.

Simply add:

turret.eulerOrder = 'ZYX';

somewhere, and three.js will now apply the Z rotation first.

  • \$\begingroup\$ Holy Cow! There's me getting all caught up in way complicated stuff just for that! Thank you so much! \$\endgroup\$ – Julian Sep 27 '16 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.