setLinearVelocity and Collisions

I’m just playing about with the excellent physics engine in JME, and I’ve got a small problem I’m trying to solve. I’ve got a simple first-person spaceship game. Currently the player’s spaceship moves forwards in the direction of the camera which I can do easily with:-

    public void simpleUpdate(float tpf) {
        // Ship uses RigidBodyControl
        Vector3f forward = ship.getLocalRotation().mult(Vector3f.UNIT_Z).multLocal(tpf);

However, if the ship collides with something, it keeps pushing into it rather than bouncing off. This is understandable since I’m continually applying “setLinearVelocity()”, but since the collisions are checked in the physics’s loop and not the game loop, how can I stop applying it immediately? Is there a simple method, or do I need to create a flag in the physics loop to say whether the ship can thrust forwards?

Thanks in advance!

Actually you should only use setLinearVelocity on the physics tick as well. The threads / loops are somewhat synced and usually the render loops update() method is safe to use but it can lead to issues / unexpected behavior when the physics update is called twice, i.e. when your frame rate goes below 25fps by default.

Thanks, that seems to have sorted it.