Creating a RigidBodyControl to represent a Ship displayed in first person mode


I have been trying to create a RigidBodyControl to represent a physical body in space. This is used to represent a ship but from a first person view. The issue I am having is that when I place the ship in space, it starts to fall as there is no ground to support it.

The reason for using a “xxxControl” class is for the collision detection and movement. (Previously i used VehicleControl but a previous post on this forum from Normen recommended using RigidBodyControl

I’ve read other posts on this forum and searched google as well as the test code. I couldn’t find anything that does something similar. Basically, I would like to implement the first person shooter example HelloCollision (with keys and movement etc) but in space (similar to the HelloPhysics example).

Any advice / pointers / help would be welcome.

The following is portions of the code I am using:

public class Encounter extends SimpleApplication {

public static void main(String args[]) {

Encounter app = new Encounter();



private BulletAppState bulletAppState;

private RigidBodyControl player;

private final Vector3f originalPosVector = new Vector3f(0, 4f, 6f);


public void simpleInitApp() {

/** Set up Physics Game /

bulletAppState = new BulletAppState();


* Configure cam to look at scene */


cam.lookAt(new Vector3f(2, 2, 0), Vector3f.UNIT_Y);




protected void initPlayer() {

// fly cam to follow player


// create player ship

BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f));

//create ship control

player = new RigidBodyControl(box, 400);









public void simpleUpdate(float tpf) {

//cam.lookAt(player.getPhysicsLocation(), Vector3f.UNIT_Y);




Many thanks,


I can’t see any ground and/or spatial…

Do you have to create a ground? As its space this should not need to be defined.

If it does, I would need to make it infinite long.

By spatial do you mean content? ( note I removed the other bits of the code, which contained the floor and bricks from the hellocollision code)

Do you have an example?



I have yet to deal with physics in ANY form or fashion, but does gravity default to ‘ZERO’? From taking a quick look at the HelloPhysics tutorial, gravity is never specified yet the balls fall as if affected by normal gravitational forces.

I noticed that you were manually setting gravity, but you commented the line out. What happens if you uncomment that line?


@jt123 said: I would like to implement the first person shooter example HelloCollision (with keys and movement etc) but in space (similar to the HelloPhysics example).

Look at the example and adapt the cam to first person.

The Gravity is normally earth gravity, you need to set it to Vector3f.Zero

i did a little javadoc research and this is what i came up with…

try moving player.setGravity(Vector3f.ZERO); to a place AFTER you add the control to the physics space.

taken from PhysicsRigidBody javadoc (inherited by RigidBodyControl):

public void setGravity(Vector3f gravity)

Set the local gravity of this PhysicsRigidBody

Set this after adding the node to the PhysicsSpace, the PhysicsSpace assigns its current gravity to the physics node when its added.


gravity - the gravity vector to set


if your players will always be in space, you could simply set the gravity of your entire PhysicsSpace to ZERO before you add anything to it, so all spatials will have the same value applied.

taken from PhysicsSpace javadoc:

public void setGravity(Vector3f gravity)

Sets the gravity of the PhysicsSpace, set before adding physics objects!


gravity -

if all you need it for is collision detection, you can just make it kinematic, but it won’t get affected by any physics forces but it can apply forces to other non-kinematic objects

Thanks all!! Decoy’s solution did the trick.