I’ve been trying to get the physics system Per and DarkProphet wrote working with the GameSystem DarkProphet created in the UserCode section. So far I’ve been unable to get even the simplest demo working and I have the feeling it’s something so simple I’ll never figure it out.
Right now I’m using a GameEntity for each spatial. The GameEntity includes a PhysicsObject that gets created when you create the Spatial. The following method gets called upon creation of a GameEntity.
private void createPhysicsObject(){
//if the spatial is not null we already have a PhysicsObject and need to remove it first
if(spatialObj != null){
PhysicsWorld.getInstance().removeObject(spatialObj);
}
System.out.println("PhysicsObject created for " + this.spatial.getName());
spatialObj = new PhysicsObject((TriMesh)this.spatial);
PhysicsWorld.getInstance().addObject(spatialObj);
}
I've set up my PhysicsWorld like so when I create a GameSystem
PhysicsWorld.create();
PhysicsWorld.getInstance().setGravity(new Vector3f(0,0,0));
PhysicsWorld.getInstance().setUpdateRate(500);
PhysicsWorld.getInstance().setStepSize(1/100f);
Then in my main update loop I have
PhysicsWorld.getInstance().update();
GameSystem.forceObtainInstance().getEntityWithName("my ship").getPhysicsObj().addForce(new Vector3f(10,0,0));
System.out.println(GameSystem.forceObtainInstance().getEntityWithName("my ship").getPhysicsObj().getLinearVelocity());
As you can see from the above code snippet I'm adding a force of 10 every update. This should make the ship I created go flying off the screen but unfortunately it doesn't move at all. The printout I have still prints out (0,0,0) for the linear velocity despite the force I manually added.
I know the GameEntity is being created, and the PhysicsObject exists otherwise I'd be getting errors. Furthermore I can get the Spatial from the GameEntity and rotate it using an InputHandler. It just seems for some reason that the force isn't being applied to the proper PhysicsObject or something.
Any ideas what I might be doing wrong?? Thank you for all the help.