Bullet + forces

So i found some force based movement code iin the bullet examples and implemented it inmy game. I relaized tho that the force is not relative to the models hpr that i want to be moved. I wan the direction its facing be the forward direction etc.

def processInput(self, dt):
        force = Vec3(0, 0, 0)
        
        if inputState.isSet('up'): force.setZ( 1.0)
        if inputState.isSet('down'): force.setZ(-1.0)
        if inputState.isSet('left'):    force.setX(-1.0)
        if inputState.isSet('right'):   force.setX( 1.0)
        
        force *= 10
        self.np.node().setActive(True)
        self.np.node().applyCentralForce(force)

This lets the models move around but wheni change the models hpr(which i parented the cameras hpr to, so to turn you just move the mouse - like an fps cmaera/movement control. Imso bad at explaining things)Im terrible with vectors and i only barely grasp whats happening in this code. and vec3 cant be reparented to the model. Any help wuld be great lol

The force vector is by default in global coordinates. So you have to transform the force vector into the global system before you apply it.

force = render.getRelativeVector(self.np, force)

:smiley: thanks! Ill give it a try once I’m home :smiley:

so i have this

def processInput(self, dt):
        force = Vec3(0, 0, 0)
        force = render.getRelativeVector(self.np, 0)
        
        if inputState.isSet('up'): force.setZ( 1.0)
        if inputState.isSet('down'): force.setZ(-1.0)
        if inputState.isSet('left'):    force.setX(-1.0)
        if inputState.isSet('right'):   force.setX( 1.0)
        
        force *= 10
        self.np.node().setActive(True)
        self.np.node().applyCentralForce(force)

but its still acting the same

No, this is not right. You have to transform it to global coordinates AFTER you have setup the force vector.

def processInput(self, dt):
        force = Vec3(0, 0, 0)
        
        if inputState.isSet('up'): force.setZ( 1.0)
        if inputState.isSet('down'): force.setZ(-1.0)
        if inputState.isSet('left'):    force.setX(-1.0)
        if inputState.isSet('right'):   force.setX( 1.0)
        
        force *= 10
        force = render.getRelativeVector(self.np, force)

        self.np.node().setActive(True)
        self.np.node().applyCentralForce(force)

aaah much better XD hehe thanks :slight_smile: