Hpr movement help

Im making a ship turnby changing its hpr, when the ship points downwards it rotates around the y axis, i need it to turn left and right even when pointing downwards, any suggestions?

I too desperately seek information on this. To see an example of what im running into, I posted code on the code snipets board. I think its the same issue.

i know the issue (i think) just no solution, when you rotate its h when the model is on the y axis it will just circle it, you need to roitate the p when it on the y axis but since the hpr counts upwards indefinitely its hard to that

Yea. I bet there is some mathematical formula where it can automatically shift which value it changes; so as P drops from 0 > + or - 90, the manipulation of H shifts to R.

Unfortunately I was a bad CS student and never took real math classes so i have no idea how to structure such a formula easily.

I believe you may be able to solve your problem by using more than one nodepath parented one under the other.
For example, call setH on the top nodepath, and setP on the child one.

also note, you can also rotate any nodepath, relative to any other. combined with a dummy nodepath you can resolve this problem without falling back to low level math.

like.

newhpr = yourship.getHpr(render)
newhpr += Vec3(1*timesinscelastframe,0,0 )
yourship.setHpr(render, newhpr )

code is totaly not tested. but something in that direction

Got it figured; set Hpr Relative to the ship itself, no need to set extra nodes. Heres the code from my updateShip method, called every frame.

Working as intended.

if (self.keyMap["forward"]!=0):
self.ship.setY(self.ship, 3)

elif (self.keyMap["backward"]!=0):
self.ship.setY(self.ship, -3)

#Left and Right
if (self.keyMap["left"]!=0):
self.ship.setR(self.ship, -1)

elif (self.keyMap["right"]!=0):
self.ship.setR(self.ship, 1)

# throttle control
if (self.keyMap["up"]!=0):
self.ship.setZ(self.ship.getZ()+.001)

elif (self.keyMap["down"]!=0):
self.ship.setZ(self.ship.getZ()-.001)

if base.mouseWatcherNode.hasMouse():
self.mousex = base.mouseWatcherNode.getMouseX()
self.mousey = base.mouseWatcherNode.getMouseY()

self.ship.setH(self.ship, -self.mousex)
self.ship.setP(self.ship, self.mousey)

I use WASD, W is forward, S is back, A and D roll the ship, E and C rise and fall, mouse controls orientation.