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
cam.setLocation(ship.getWorldTranslation());
ship.setLocalRotation(cam.getRotation());
Vector3f forward = ship.getLocalRotation().mult(Vector3f.UNIT_Z).multLocal(tpf);
ship_control.setLinearVelocity(forward);
}
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!