I’m having trouble making a node always follow the camera in the bottom right of the screen. The node is an item node, the item is what the player is holding.
I have a ChaseCamera set up and the flyCam is disabled. I have created an itemNode attached to my characterNode. I create a cube geometry and attach it to the itemNode when the user selects an item. The cameraNode is attached to the itemNode.
What I am seeing is the item floating above the player, up and to the left. When I rotate the camera it does not rotate. However when I move the player it follows my movement.
I have copied what I think is the relevant portion of code in. This is a snippet from my PlayerControl class. I’ll be happy to put the whole thing in if anyone requests it.
Any help is appreciated.
@Override
public void setSpatial(Spatial spatial)
{
super.setSpatial(spatial);
if (spatial instanceof Node)
{
Node parentNode = (Node) spatial;
parentNode.attachChild(characterNode);
this.blockTerrain = app.getStateManager().getState(RunningAppState.class).getBlockTerrain();
this.blockExplosionControl = app.getStateManager().getState(RunningAppState.class).getBlockExplosionControl();
this.itemControl = app.getStateManager().getState(RunningAppState.class).getItemControl();
this.gunControl = new GunControl(app, this);
characterNode.addControl(gunControl);
characterNode.setLocalTranslation(getPlayerStartLocation());
characterNode.setUserData("player", this);
this.playerHeight = cubeSettings.getBlockSize() * 2;
physicsCharacter = new BetterCharacterControl((cubeSettings.getBlockSize() / 2), playerHeight, 5);
characterNode.addControl(physicsCharacter);
physics.getPhysicsSpace().add(physicsCharacter);
physicsCharacter.setDuckedFactor(0.5f);
physicsCharacter.setJumpForce(new Vector3f(0.0f, 125.0f, 0.0f));
physicsCharacter.setGravity(new Vector3f(0.0f, -70.0f, 0.0f));
// Disable the default flyby cam
flyCam.setEnabled(false);
initChaseCamera();
this.itemNode = new Node("item");
this.cameraNode = new CameraNode("camera node", cam);
this.cameraNode.setEnabled(true);
this.cameraNode.setControlDir(CameraControl.ControlDirection.CameraToSpatial);
this.characterNode.attachChild(cameraNode);
characterNode.attachChild(itemNode);
itemNode.attachChild(cameraNode);
}
}
private void initChaseCamera()
{
chaseCam = new ChaseCamera(cam, characterNode, app.getInputManager());
chaseCam.setMinDistance(0.1f);
chaseCam.setMaxDistance(0.1f);
chaseCam.setInvertVerticalAxis(true);
chaseCam.setDragToRotate(false);
chaseCam.setLookAtOffset(new Vector3f(0.0f, cubeSettings.getBlockSize(), 0.0f));
chaseCam.setDefaultVerticalRotation(0);
chaseCam.setDefaultHorizontalRotation(FastMath.DEG_TO_RAD * 270);
}