GhostControl following with a delay?

I have attached a GhostControl to a Geometry, and I noticed 2 strange thing:

As the Geometry is moved arond, GhostControl follows it with a slight delay, as shown in the image below:

Is it supposed to behave like this?

Secondly, sometimes the GhostControl is not even attached to the Geometry!

Here is the code
[java]

    Geometry bulletg = new Geometry("bullet", bullet);
    Material mat = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
    mat.setColor("Color", ColorRGBA.Red);   // set color of material to blue
    bulletg.setMaterial(mat);
    bulletg.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    bulletg.setLocalTranslation(cam.getLocation());
    GhostControl ghost = new GhostControl(
            new SphereCollisionShape(0.4f));  // a box-shaped ghost
    bulletg.addControl(ghost);                         // the ghost follows this node
    bulletAppState.getPhysicsSpace().add(ghost);
    bulletg.addControl(new SpellControl(cam.getDirection(),shootables,ghost));
    rootNode.attachChild(bulletg);
    bulletAppState.getPhysicsSpace().add(bulletg);

[/java]

And in the SpellControl

[java]
protected void controlUpdate(float tpf) {

    if(spatial != null) {
        spatial.move(facing.divide(40f));

[/java]

What if you added your spell control before the ghost control?

Like this?

[java]
Geometry bulletg = new Geometry(“bullet”, bullet);
Material mat = new Material(assetManager,
“Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material
mat.setColor(“Color”, ColorRGBA.Red); // set color of material to blue
bulletg.setMaterial(mat);
bulletg.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
bulletg.setLocalTranslation(cam.getLocation());
GhostControl ghost = new GhostControl(
new SphereCollisionShape(0.4f)); // a box-shaped ghost
bulletg.addControl(new SpellControl(cam.getDirection(),shootables,ghost));
bulletg.addControl(ghost); // the ghost follows this node
rootNode.attachChild(bulletg);
bulletAppState.getPhysicsSpace().add(bulletg);
bulletAppState.getPhysicsSpace().add(ghost);
[/java]

I have the same result :frowning:

So what is the problem? Your users won’t see the debug display anyway.

If this is the intended behaviour, then it’s ok (I thought that this was a mistake on my part).

However, there is still the other problem (the GhostControl is not even attached to the Geometry).

In the image below, only the “youngest” geometry has a GhostControl.

This happens when I throw a several geometry in quick succession and the geometry itself is “slow”

[java]spatial.move(facing.divide(40f));[/java]

When is “fast” it doesn’t happen

[java]spatial.move(facing.divide(4f));[/java]

I can’t see from the image what you mean by “this happens”. Anyway you have to think about the fact that this is effectively two objects, the bullet object and the spatial. Ghost objects and kinematic physics objects get their location from the spatial, for normal physics objects the spatial gets its position from the physics object. So depending on when you look at the whole system (control order) there will be a seeming delay in one or the other direction. Effectively this doesn’t pose a problem though as you have a system with continuous time.

1 Like

Sorry, maybe I didn’t explain well my problem.

The intended behaviour is that I “throw” a red ball Geometry with attached a GhostControl.
In the image above, you can see 4 red Geometry but only 1 GhostControl!
And I can confirm that there is only 1 GhostControl not only from the debug window, but also because the “Ghostless” geometry does not detect collision (as the Ghost is supposed to do).

This problem is completely unrelated to the “delay” question. Is not that the other 3 Ghost are delayed, they just not exist.

To recap: 3 Geometries are spawned without a Ghost, and the last is spawned with a Ghost

does each red ball have a separate GhostControl? (you can’t share them)

Yes, as you can see from the code above I’m creating a new GhostControl for each new Geometry…

I wonder thats the reason why FPS games have “interp” or maybe its latency as well.

@Jacob: Sorry, I did’t understand what you mean…

When playing online fps games (e.g Counter Strike,COD,Titanfall) when you shoot enemies, sometimes if they are moving behind a physical object like a wall you might kill them but in their perspective they are behind the wall. So as a entity moves the ghost control has a bit of a delay and you can hit the ghost control but the player might already be behind a wall. Its just a thought as i see it alot when i play.

@Pesegato this “out of sync” is because physics calculating positions in one thread and spatials in another, so when physics run at 60fps and visible game at 40fps, there needs to be some compensation between missing fps. also i think debug data is grabbed from physics earlier than from spatial, so it is rendered a bit backwards.

i think geometry and physics are similar to two cars driving in two lanes and trying to drive exactly one next to another. you cannot be 100% accurate ever