Hello!
The question is based on the following code:
import com.jme.input.NodeHandler;
import com.jme.math.Vector3f;
import com.jme.scene.CameraNode;
import com.jme.scene.shape.Box;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.geometry.PhysicsBox;
import com.jmex.physics.util.SimplePhysicsGame;
public class TestPlayerBody extends SimplePhysicsGame {
@Override
protected void simpleInitGame() {
// Ground
StaticPhysicsNode ground = getPhysicsSpace().createStaticNode();
Box groundBlock = new Box("Sol", new Vector3f(), 5f, 0.5f, 5f);
groundBlock.setLocalTranslation(new Vector3f(0, -1, 0));
ground.attachChild(groundBlock);
ground.generatePhysicsGeometry();
// Player
DynamicPhysicsNode playerNode = getPhysicsSpace().createDynamicNode();
// DynamicPhysicsNode playerHead =
// getPhysicsSpace().createDynamicNode();
// DynamicPhysicsNode playerBody =
// getPhysicsSpace().createDynamicNode();
// playerNode.attachChild(playerHead);
// playerNode.attachChild(playerBody);
PhysicsBox playerVolume = playerNode.createBox("Player volume");
playerVolume.setLocalScale(new Vector3f(0.5f, 1f, 0.5f));
playerNode.setLocalTranslation(0, 2, 0);
playerNode.setCenterOfMass(new Vector3f(0, -0.25f, 0));
// Player mouse control
input = new NodeHandler(playerNode, 5f, 1f);
// Place the Camera so that it watches the scene n_n
CameraNode camNode = new CameraNode("Camera Node", cam);
camNode.setLocalTranslation(0, 1, -4);
// playerNode.attachChild(camNode);
// Root
rootNode.attachChild(ground);
rootNode.attachChild(playerNode);
rootNode.attachChild(camNode);
// Misc
showPhysics = true;
}
public static void main(String[] args) {
new TestPlayerBody().start();
}
}
You may notice that playerHead and playerBody creation are commented, as well as playerNode.attachChild(camNode).
Running this code shows:
A physics box falling on a floor.
The mouse and WASD make the "player" move, fps style. The camNode has not been attached on purpose, I want to see how the PhysicsBox behaves.
->
Turn left right, WASD: Works nicely.
Look up/down: Unlike an fps game would do, your head bobs back and forth until it stabilizes.
So, smart me, I wanted to create to "parts" for my player:
- head
- body
both are attached to playerNode.
playerNode is controlled using WASD and left/right rotation. However I'd "lock" up/down mouselook.
The "head" would be the only one affected by that up/down mouselook.
But, a DynamicPhysicsNode cannot be attached another DynamicPhysicsNode. So I can only understand my genius idea wasn't that right, in the end.
How would you cope with this mouselook issue?
Thanks for your time!!!