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]
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 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.
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
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