I just switched my game over to FixedLogicRateGame from SimpleGame to try and keep the updates per second consistent. Without a fixed update rate the reponsivness of the physics varies depending on how fast the machine can loop through update.
I’ve come across a problem which I haven’t been able to figure out. I’m not quite sure if it’s a physics system thing or a general jME thing so I put the question here.
Right now I am using the default FixedLogicRateGame which is 60 updates per second. That means 60 times a second my update method gets called and the position of objects are updated as well as keyboard input polled. (at least that’s how I understand the FixedLogicrateGame works)
The strange thing is that as I fly my ship around (which is a PhysicsObject and has forces applied to it) the thrusters attached to it start to fall behind. In other words they don’t say attached to the ship. I update the position of the thrusters using a controller attached to the ship. My guess is that the PhysicsSystem is updating the position of the ship faster than 60 updates per second. Therefore, the thrusters have their position updated only 60 times per second and can’t keep up with the ships position which is being updated more often.
I thought I could solve this by having the PhysicsWorld update rate match that of my games update rate. So I went in and did
The idea was that the physics sytem and the game update() call will now update at the same rate and the syncing problem between the thrusters and the ship would go away.
The problem now is that the ship stutters everywhere. It violently vibrates as it moves around and it seems like the thrusters are still lagging behind.
If I use BaseGame then I have no problems other than the fact that everything slows down as I add more overhead to the update calls.
Me and per are very aware of this problem! And frankly, its getting very very annoying!
The PhysicsSystem’s update method is controlled by two pathways. The first is the frequency of the AbstractGame’s update(float time) method. And secondly, by its own internal timer.
It seems the only way around this stuttering behaviour is this:
Notice the lack of a setUpdateRate(...) call. This will actually disable the internal timer of the physics system and let it run as fast as possible. I.e only restricted by the outter AbstractGame timer...
This seems to give me a solid and smooth simulation. E.g. Our GDC demo uses this method (however, it uses FixedFramerateGame, i just tried it with FixedLogicrateGame and the solution is still the same).
I think i know the solution to the problem (the internal timer is out of sync with the external one), so i think you can probably see a change soon.
Right, I havn’t liked that internal jme timer anyway
I think we can do the timing by just putting an elapsedTime variable in PhysicsWorld. This would of course require the update method to take the time since the last frame as an argument.
Ok, committed… could you see if it makes your problem go away? Note: this will break your code as you now have to pass a “time since last frame” parameter to the update method. This shoudln’t be a problem though, since it’s just a one line change: update(tpf)… not rocket science
Also, is it just me? or does the tests actually run smoother? :o
This got rid of the stuttering but now I have the problem where the thrusters on the ship lag behind.
Basically I have a ship which is a geom and a physicsObject for that ship. Then using a modified version of per's ship thruster code (he posted it in another forum) I create a jetEffect controller and attach that to the ship. The jetEffect controller has an update method that adjusts the thrusters position to always be right at the back of the ship.
If I extend BaseGame and disable the PhysicsSystem internal timer (i.e., no setUpdateRate()) then everything works peachy. No stuttering, no thrusters lagging behind. If I switch to FixedLogicrateGame then the thrusters lag (although the stuttering went away)
My guess is the update call for the jetEffect controller is getting called less often then the ship location is getting updated so it begins to fall behind.
I connected to cvs and got the newest source but I’m not sure how to use it 8-O
Is there an easy to way to build a new jar? (I’m using eclipse) or maybe just point eclipse at the new project and tell it look their for any files it needs?
Is there an easy to way to build a new jar? (I'm using eclipse) or maybe just point eclipse at the new project and tell it look their for any files it needs?
Yes! If you checked out jme-physics as a java project, the latter can be achieved by right clicking on your game project and then choose Properties -> Java Build Path -> Projects and check the jme-physics project. And you're done :)
If you want to create a jar, there are several ways to go, among others you can use the jar command. However, I find it easiest done by just creating a zip file from the directories involved, and then change the suffix to .jar (zip and jar use the same compression).
Note: make sure to remove the old physicsSystem.jar from your path!
That’s odd … the jmePhysics project I checked out doesn’t appear in the projects list despite being there in the resource view.
When I right click on the jmePhysics project I noticed it’s missing a lot of options that the other projects have such as Java Build Path and Java Compiler etc.
Do I have to explicitly tell Eclipse that jmePhysics is a project?
Of course now everything is totally broken cause I have to go through and change to DynamicPhysicsObjects and StaticPhysicsObjects but I was gonna have to do that at some point anyway. Might as well be now
I’ll let you know if the update thing fixed everything once I get everything converted over.
okay … I switched over to the newest build of the PhysicsSystem and have some problems.
The first problem is the same problem I’ve had all along with the thrusters not staying attached to the ship. For example, if you just move straight up with your ship the thruster slowly starts lagging behind in the back and seperates farther and farther.
The second problem is my ship won’t rotate anymore. I didn’t really change any code other than change all my PhysicsObjects to DynamicPhysicsObects and do the casting. (I"m not rotating using the PhysicsSystem but just rotating the actual geometry)
Here is the rotation code which was taken from the RotateKeyNodeAction class.
Am I missing something or do I have to do something different with the new PhysicsSystem? I know the method is getting called and that the correct objects are being used since I printed out the names before. Also I know the PhysicsObject is dynamic cause I printed out the results of isStatic() which was false.
Just for kicks I tried changing the translation of the object in the above code. So I added
This actually made my ship move to the right like it should. So either my rotation code is broken or something is wrong with the PhysicsSystem that doesn't allow it to update on rotations. My guess is it's my code cause my code is always suspect. I'm looking more closely right now at the rotation code.
private static final Vector3f tempVa = new Vector3f();
private static final Matrix3f incr = new Matrix3f();
private static final Matrix3f tempMa = new Matrix3f();
private static final Matrix3f tempMb = new Matrix3f();
Has it been committed? I’m checking the CVS repository now and the syncWithGraphical method stills seems to be the same.
In eclipse I was just right clickin the jmePhysics Project going to Team and then going to Update.
Am I doing something wrong there?
Thanks for the speedy patching by the way.
----
I just fixed the line in my local version for now
The thruster still slowly detaches itself from the model which seems to suggest that the physicsModel and Geometry model still aren’t in sync. I’m using the newest version of the PhysicsSystem where you pass the tpf to the update call and don’t throttle the PhysicsUpdates at all.