Changed outcome of phycics if framerate changes

Hey guy,

I’m new to jME and are currently playing around with physics. I have a very basic setup. Just a floor with 0 mass and one CollisionShape. The shape has a mass of 1.0f and I’ve added the following TickListener

[java]
bulletState.getPhysicsSpace().addTickListener(new PhysicsTickListener()
{

		@Override
		public void prePhysicsTick(PhysicsSpace space, float tpf)
		{
			copter.getPhysicsControl().applyCentralForce(new Vector3f(0, 8, 0));
		}
		
		@Override
		public void physicsTick(PhysicsSpace space, float tpf)
		{
			
		}
	});

[/java]

So the first thing I want to note here is that from my physical knowledge I would require around 10N of force to move anything, right? F = 10 m/s^2 * 1kg = 10N. But the shape actually moves upwards. And that’s were strange things happen. It moves upwards to around 10m (assuming it’s fine to use meters here) and than drops down like the force has been reduced). Every time I run the application and check the hightest point until that happens, it’s somerwhere else. I wanted to record this with Bandicam and I noticed an even more strange thing: Due to my poor laptops hardware the framerate drops down from 60FPS to ~20FPS. And suddenly the shape starts to move up again (even if it already began to fall down).

I’ve done extensive testing to locate my mistake but the physic completely glitches out if I start recording and the framerate drops down.

I’ve compiled jMonkeyengine from the git branch 3.0 which states to be 3.0.10 and the log output complies with that. I don’t know if that’s the last stable version because the download page does not tell me which is the current one. I’m using it with eclipse and maven. Since I don’t want to do actual game development but visualize a quadrocopter controll (very basic stuff, actual real world physics are not required so please don’t tell me to use something else), I don’t need the SDK and don’t want to use it.

I’ve often read that the physics calculation is actually frame independent. After expiriencing these issues I’m not so sure if that is true. Can someone explain to me what is going on? In case someone want’s to seem my whole code, here is the important part that sets up most of the physics stuff.

[java]
public void simpleInitApp()
{
assetManager.addAssetEventListener(new AnisotropicFiltering(8));

	// add resource folder to asset manager
	assetManager.registerLocator("res", FileLocator.class);
	
	// init fields
	copterManager = new CopterManager();
	
	// set up scene and physics
	axisArrows = new AxisArrows(10);
	rootNode.attachChild(axisArrows);
	
	floor = new GridFloor(1000);
	rootNode.attachChild(floor);
	
	flyCam.setMoveSpeed(1);
	cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(), 0.01f, 1000f);
	cam.setLocation(new Vector3f(1, 1, 1));
	cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
	
	initPhysics();
	
	initCopter();
	
	// init sun
	DirectionalLight sun = new DirectionalLight();
	sun.setColor(ColorRGBA.White);
	sun.setDirection(new Vector3f(-.5f,-.5f,-.5f).normalizeLocal());
	rootNode.addLight(sun);
	
	/* Drop shadows */
    final int SHADOWMAP_SIZE = 1024;
    DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);
    dlsr.setLight(sun);
    viewPort.addProcessor(dlsr);
}

private void initCopter()
{
	copter = copterManager.getCopter("military");
	rootNode.attachChild(copter.getNode());
	bulletState.getPhysicsSpace().add(copter.getPhysicsControl());
}

private void initPhysics()
{
	bulletState = new BulletAppState();
	stateManager.attach(bulletState);
	
	bulletState.getPhysicsSpace().addTickListener(new PhysicsTickListener()
	{
		
		@Override
		public void prePhysicsTick(PhysicsSpace space, float tpf)
		{
			copter.getPhysicsControl().applyCentralForce(new Vector3f(0, 8, 0));
		}
		
		@Override
		public void physicsTick(PhysicsSpace space, float tpf)
		{
			
		}
	});
	
	// render collision boxes
	bulletState.setDebugEnabled(true);
	
	// set up floor collision
	CollisionShape floorShape = new PlaneCollisionShape(new Plane(Vector3f.UNIT_Y, 0));
	
	// create physic control
	RigidBodyControl floorControl = new RigidBodyControl(floorShape, 0f);
	
	// add to physics space
	bulletState.getPhysicsSpace().add(floorControl);
}

[/java]

I investigated this a bit further. I made the force toggleable by pressing X. After the initial alignment of the shape on the ground it bounces for a moment and than goes to idle. If I apply the 8N force after that, nothing happens (as it should), but if the force is applied before the shape touches the ground than the thing from above happens. So this is my conclusion but I would really like to hear someone commenting on that, that knows what he’s doing.

The screen capturing software forcefully changes the framerate in a way jME does not expect it and the physics thinks that much more time has passed than it actually has and applies too much force. (But I don’t get why it does not apply too much gravity because of the same reason. The shape never drops, I tested that by letting it run a few minutes).

And for the initial thing: The bounce that happens once the shape reaches the ground after the physics are in place causes so much upwards velocity that the shape get’s launched up and since 8N are applied this movement is not stopped.

But I’m still curios if that’s the reason. The physics look good now, but I’m still concerned that I might encounter more problems later.

PS: Can I edit my post somehow?
PPS: Seems like I can any post but the first one. Why that?

Read this: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics
And the javadoc for PhysicsSpace.setMaxSubsteps