Ship mesh and colision shape out of sync at very high speeds

Hello, i have problem with physics-to-model location and rotation syncing. I was inspired by default jmonkey vehicle control and tried to implement space ship in similar way.

Ship almost stopped

Ship at very high speed jittering between distant position and synced position

Interesting fact is, when i give spatial to the delayedcamera, then camera is perfectly synced with spatial, and when i give it shipPhy it is perfectly synced with shipPhy, no jitter at all. i dont know why ship mesh is out of sync with ship physics :frowning:

With increasing speed, physics collision shape seems to be more and more distant from mesh and jitters. When i accelerate ship to ultra high speed about 100km/s mesh start blinking and with more speed it disappears. I dont know what im doing wrong, i dont want low speeds in space sim :slight_smile:

sources are here:
LevelAppState http://pastebin.com/XbZF8eTB
SpaceShipControl http://pastebin.com/2hgVqPfa
PhysicsSpaceShip http://pastebin.com/xVvF0qwE

any suggestions? :slight_smile:
thanks
Ascaria

where is edit button? :slight_smile:

edit: you can reproduce this easily, just make any object move at high speed, for example one million km/h

An (educated) guess:

If you’re moving high speeds, are you travelling large distances? Remember everything is floats, not doubles, so you would quickly hit precision problems with those kind of speeds and distances if you’re using game units and no scaling or other tricks. I suspect they are “aligned” just to the limits of precision for the distance from the origin (or speed, for very high values).

Its just the debug display.

i cannot agree, it is not just debug display, i have gun exactly at the tip of the ship and stationary fire is ok, but rotated and moving, firing balls is out by some weird offset. i do not care if ship jitters by 100 meters, but model and physics and camera must jitter by absolute same way, so in relative position to each other, it appears to be calm. in tutorial, there is something about physics trying to do some interpolation, some compensation if fps is lower, what about fix physics ticks with framerate ticks, this could help with relative aligning

edit: how could i fit physics exactly to frame rate, so update of all things is done always in same order ?

@Ascaria said: i cannot agree, it is not just debug display, i have gun exactly at the tip of the ship and stationary fire is ok, but rotated and moving, firing balls is out by some weird offset. i do not care if ship jitters by 100 meters, but model and physics and camera must jitter by absolute same way, so in relative position to each other, it appears to be calm. in tutorial, there is something about physics trying to do some interpolation, some compensation if fps is lower, what about fix physics ticks with framerate ticks, this could help with relative aligning

A physics tick is done, the locations and rotations are transferred to the scenegraph, all sequentially. What you suggest is already implemented. Also as was suggested by others, you should really think about your scales, 100km/s is totally overblown if you still use 1unit=1meter.

then i need some tips how i could achieve something like frontier first encounters… :frowning:

@Ascaria said: then i need some tips how i could achieve something like frontier first encounters... :(

Hint: They also didn’t use meters.

1 Like

but if they didnt use meters, how then could be possible (and i did it and it was smooth) miss planet at 10000km/s in real time. i think, i have culprit. when i set following:
[java]
getPhysicsSpace().setAccuracy(1f);
getPhysicsSpace().setMaxSubSteps(1);
[/java]
so that physics tick is every 1 second, then i run my game, then physical location of my model is updated every whole second and it appears as jumps every second, but mesh goes smoothly between these two steps, which is nice, but i rather prefer to mesh follow physics exactly, so it is stepped after whole second. how can i do that? :slight_smile:

You are misunderstanding the accuracy and substeps, read their javadoc.

10000 km/s divided by 60 is about 166 km/s, 10000 km/s divided by 1 is still 10000 km/s, meaning every physics step your ship moves either 166km or 10000km on each tick, anything in between is interpolated and there is no collision detection. So if your planet diameter is below that the ship will just warp though it.

Also, you will want to separate your game. If ships fight, just make a (small) physics space in the fight zone, if they travel from planet to planet you don’t need to use any physics at all, just make it look like its traveling or entering hyper space or whatnot.

ok i got the point, i will try to think different way.

last question, can i somehow turn any interpolation off?

Why would you want to? Then your ship jerks from one 166km to the next.

because ship jerking is ok when ship location is correctly synced with camera location

im at vector [2 100 000, 2 000, 1 500 000], stopped ship via shipPhy.setLinearVelocity(Vector3f.ZERO); and stacional ship jitters and blinks and firing is not aligned :frowning: why is that?

How about you set the camera location according to the spatial location? And again, your value ranges are much too large.

im setting camera location and rotation as

[java]
@Override
protected void controlUpdate(float tpf)
{
if(enabled && null != spatial) {
// Vytáhneme si akutuální rotaci kamery
Quaternion cameraRotation = cam.getRotation().clone();
// Odrotujeme ji o kousek směrem k rotaci spatialy
cameraRotation.slerp(spatial.getWorldRotation(), tpf);
// Nastavíme kameře novou rotaci
cam.setRotation(cameraRotation);
// Odsuneme kameru za spatialu
cam.setLocation(spatial.getWorldTranslation().add(cameraRotation.mult(offset)));
}
}
[/java]

Then if you get an offset you either change the cam position too early or change the spatial / cam position afterwards. You can also try and use the physics location because that might already be computed from the last physics update but the controls weren’t worked off yet so the spatial is still in the last frames position.

What scale are the ships? With those numbers you could be hitting precision errors, you’ll have accuracy at the metre/single unit level, but not at the 10cm level - how far out of line are the meshes?

Of course it could be something more complicated, but with numbers in the 2 million range, you’ll not have any precision at the sub-metre level.

Simple code to illustrate my point:
[java]public class testPrecision{

 public static void main(String []args){
     float a = 2100000f;
     for (int i = 1; i < 100; i++) {
        System.out.println("a = " + (a+(i/10f)));
     }
 }

}
[/java]

The output “should” count in 0,1 increments…but it doesn’t. Drop a to 210 say and it will.

Its my fault, i thought float is precise the same at 0,0,0 (lets say 0.00001) or at 1000000,0,0 (lets say 1000000.00001). idea of great distances thrown away :slight_smile: i must orient scene around 0,0,0 thanks for replys :slight_smile:

ascaria