Custom NodeHandler for first person camera


This topic is linked to:

But as it does not concern Phisics, this part of the problem sits here in the General forum.

I'm trying to make a physical body for the first person "player". If you have any suggestion or tutorial related to making 1st person camera or else, I'll be glad to get them…

So! Situation now: I have two parts for my "player": Body and head, both are DynamicPhysicsNode.

  • The body must be able to turn left/right using the mouse
  • The head must be able to look up and down using the mouse

    But looking up/down must be prohibited for the body node while the head node may not turn left right. I hope it makes sense.

    I'm stuck with mouseLook.setLockAxis - I've made two "custom" handlers based on NodeHandler:
  • one for the head: HeadNodeHandler
  • one for the body: BodyNodeHandler

    I can't figure out how to modify the NodeHandler class to that end.

    The following code seems to control the mouselook:

    private void setUpMouse( Spatial node, float mouseSpeed ) {
        RelativeMouse mouse = new RelativeMouse("Mouse Input");
        mouse.registerWithInputHandler( this );

        NodeMouseLook mouseLook = new NodeMouseLook(mouse, node, 0.1f);
        mouseLook.setSpeed( mouseSpeed );
        mouseLook.setLockAxis(new Vector3f(node.getLocalRotation().getRotationColumn(1).x,

Ow  :?
There's also that setActions method.
I'm tempted to ask: "Where should I modify what?"

Please help...

Ok, I'm using a different way which seems to solve the case.

Still not sure of that, I won't yet disclose the code :frowning:

Not sure, because despite I read I can't understand how to modify NodeMLouseLook to prevent from "looking too low or too high".

Help welcome :slight_smile:

In most FPS situations, you actually don't animate the physical collision proxy when the head moves. Instead, you only move the visual representation. Your player could be a simple capsule, or a "lollipop" (sphere or capsule on top of a ray).

For the camera, my preferred method is to keep yaw and pitch in two separate variables, and update those when you receive mouse movement. Then, each frame, you turn yaw and pitch into a quaternion. For yaw, you can modulo it with 2*PI to make sure it doesn't go too high/low. For pitch, you can clamp it to some reasonable range, such as +/-1.4 or so. (Assuming radians).

Thus, you hook the physical representation to a given node. Then you hook the camera to another node slaved off of that. You drive the orientation of the camera node based on the pitch and yaw that you drive off of the mouse movement.