Rotation problem

Hello everyone, been working on a little project with nodes and stuff, if i press W it goes forward, problem is that im trying to get it so that when i press the D key, it rotates the object (which it already does) on the screen, but if i continue to press W to go forward with the new direction of the object is supposed to be going, it is not



For instance, Press W to go forward in space ship, press D to turn space ship to the right, if i press W again, it does not go the new direction the ship is facing, instead it continues to go the original forward direction.



Sample code for when i press the D key:

( b is the object, bNode is the node that has the object and camNode attached to it)



[snippet id=“70”]

First, don’t use: getRotationColumn()



It is not the best way to do what you want.



Use:

Vector3f direction = bNode.getLocalRotation().mult( Vector3f.UNIT_Z );



Second, rotate() is taking radians… so you are actually rotating 572 degrees per second. Because you are doing more than full rotations it just happens to look right to you but it’s likely to bit you later.



None of that should be causing your problem but it’s important to get things right, also.



I do notice that you are rotating something called “b” but you are using the rotation of “bNode”… perhaps this is the source of the error.

All that b.rotate does is it turns the spaceship spatial, whereas the bNode contains the spaceship spatial, the camNode camera…



Imagine your sitting behind a ship looking at the back half, ship in front of you turns to look at his right side, but when he hits the gas, he is going the direction your looking, which is the original way he was.



This is what is happening, soon as i press to go forward, the ship is still going the original way it was facing. What i want it to do as soon as i turn, and press forward, to go the new direction its facing,…



Should i post my full code?

@cavalierconcepts said:
All that b.rotate does is it turns the spaceship spatial, whereas the bNode contains the spaceship spatial, the camNode camera...

Imagine your sitting behind a ship looking at the back half, ship in front of you turns to look at his right side, but when he hits the gas, he is going the direction your looking, which is the original way he was.

This is what is happening, soon as i press to go forward, the ship is still going the original way it was facing. What i want it to do as soon as i turn, and press forward, to go the new direction its facing,...

Should i post my full code?


We'll need to see the code where you turn bNode then.

Thats the problem, thats the code i have so far to make it turn, and im not quite sure what to do from here…



If i rotate my bNode, it screws everything up, something is wrong with the code…



[snippet id=“71”]

You never change the rotation of bNode.

Okay, so, would i attach a pivot to bNode and then rotate the pivot instead, would that rotate everything?

I have no idea what you are trying to do exactly. But I do know that:

bNode.getLocalRotation()



…will not do anything for you if you never change the local rotation of bNode. Am I making sense?

Got it to work just fine, what i did was detached camNode from bNode, and attached it to rootNode, then added code to make camNode to follow bNode as i moved the ship, this way, when i do bNode.setLocalRotation as im turning the ship, it doesnt screw up.



Now to fix my mouse rotate handlers…