Hi!
Looked at the previously asked questions of this kind, but couldn't manage to build my own answer.
Help requested:
The camera will be attached to a DynamicPhysicsNode:
@Override
protected void simpleInitGame() {
(...)
self = getPhysicsSpace().createDynamicNode();
self.createBox("First person body");
self.setLocalScale(new Vector3f(1, 2, 0.5f));
self.setLocalTranslation(new Vector3f(0, 1, 0));
self.setCenterOfMass(new Vector3f(0, -0.5f, 0));
rootNode.attachChild(self);
selfLocation = self.getWorldTranslation();
camLocation = new Vector3f(self.getLocalTranslation().x, self.getLocalTranslation().y, self.getLocalTranslation().z);
cam.setLocation(camLocation);
showPhysics = true;
(...)
}
I'll perhaps be wrong, but I'm tempted to say:
1) the camera position is linked to key inputs:
input.addAction(
new InputAction() {
@Override
public void performAction(InputActionEvent e) {
if (e.getTriggerPressed()) {
self.getMaterial().setSurfaceMotion(
new Vector3f(0, 0, -2));
} else {
self.getMaterial().setSurfaceMotion(
new Vector3f(0, 0, 0));
}
}
}, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_NUMPAD8,
InputHandler.AXIS_NONE, false);
@Override
protected void simpleUpdate() {
camLocation.set(self.getLocalTranslation().x, self.getLocalTranslation().y + 1, self.getLocalTranslation().z +3);
cam.update();
}
2) the camera steering is linked to cam.getDirection()
-> ?
I feel I'm going the wrong way!
When moving the mouse how should in best practices the "self" DynamicNode be rotated? Should it be linked to the mouse input for x-z, leaving y mouse axis for the cam itself? I feel that's too messy to be right :( Moreover, I don't feel confident at making it :(
Also, can one please tell me the difference between getLocalTranslation and getWorldTranslation?
The screen flickers as the second one is used to set the cam location:
camLocation.set(self.getLocalTranslation().x, self.getLocalTranslation().y + 1, self.getLocalTranslation().z +3);
// camLocation.set(self.getWorldTranslation().x, self.getWorldTranslation().y + 1, self.getWorldTranslation().z +3);
Thanks for your time!