Applying Torque to NodePath in direction camera is facing

Okay, so i have a panda inside a ball. (bullet sphere). I have code where i can apply torque, but, i have a camera gimbal set up around it where id like to apply the torque the direction the camera is facing. (Think like Marble Blast Ultra).

I think I need the getRelativeVector() function, but im def not using it right. HELP =b

The gimbal set up is 2 nodes, one x (only changes heading), one y (only changes pitch), camera parented to y, y parented to x and x parented to render. (at the moment, id like it to be parented to ball but then it rotates. )

They are on gimbals to avoid loss of degree of freedom.

 def processInput(self, dt):
        torque = Vec3(0, 0, 0)

        # you need ot set force and torque in relation to the camera x y plane
        #torque_direction = 
        #la = self.lookAt(self.sphereNP)
        #orient = self.gimbal_x.getRelativeVector(self.boxNP, Vec3(0,1,0))
        #orient = Vec3(self.gimbal_x.getHpr(self.boxNP)).forward()
        if inputState.isSet('forward'): torque.setY(1.0)
        if inputState.isSet('reverse'): torque.setY(-1.0)
        if inputState.isSet('left'):    torque.setX(-1.0)
        if inputState.isSet('right'):   torque.setX(1.0)

        torque *= 10.0

        torque = render.getRelativeVector(self.gimbal_x, torque)


Wow, i actually had it… I had the X and Y reversed. I was thinking rotate towards a direction but its actually about an axis which in hindsight makes much more sense.

if inputState.isSet('forward'): torque.setX(-1.0)
if inputState.isSet('reverse'): torque.setX(1.0)
if inputState.isSet('left'):    torque.setY(-1.0)
if inputState.isSet('right'):   torque.setY(1.0)
1 Like