Rotating nodes across multiple classes


I’ve been struggling with this for quite some time now.

First, some back-story: I made a single file project(only one .java) and made sure everything was working as I wanted it to. I managed to get everything working and started to break everything up into separate classes, such as Player, Lights, etc.

Now to my issue. I had some code, which I can provide if necessary, which made a node rotate in accordance with the camera’s front view vector(so, where the camera was looking at). Once I separated the node from the class where it was being told to rotate, it stopped(I added the relevant code to the rotation lines so that it was pointing to the node in the new class).

The rotation is happening in the SimpleUpdate() method in the main class, as it was previously. What I’ve noticed, upon printing out the node’s rotation before and after the transformation, is that the node’s rotation is always 0 before and wherever the camera is pointed at afterward.

I’ve already check the node’s usages to see if I was resetting it by mistake, found nothing.

I changed from setLocalRotation() to rotate(), which changed nothing.

I changed from having the node rotate, to having it’s child(spatial) rotate, and the spatial rotated as it should.

I’ve checked the code various times now to make sure it was the same as when it was working and cannot find any changes, so I have no idea why it’s not working. Hope someone here can help me out.

The code I have right now:

In the main class:

[java] player.nHead.setLocalRotation(new Quaternion(


, cam.getRotation().getY()

, 0

, cam.getRotation().getW()


In the Player class:

[java]health = 10;

nHead = new Node(“Head node”);

character = new CharacterControl();

CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(8f, 4f);

character = new CharacterControl(capsuleShape, .05f);




head = assetManager.loadModel(“Models/fluWithAnim.j3o”);

Material headMat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

headMat.setColor(“Color”, ColorRGBA.Blue);



nHead.setLocalTranslation(0, 50, 0);




Close, but not exactly what I needed.

The way I had it setup before, or rather, the way I want it to work, is that as the player is walking(I have a boolean already setup and working for this) the character(nodes, spatials, etc) would follow the camera’s direction and when he stopped walking, the camera would freely rotate around the character(which no longer rotates). I just tried some work-arounds with what you gave me and couldn’t find a solution for what I needed.

Also, could you tell me why the nodes don’t like being interacted with across classes, in case I run into it again/a similar issue? I’d rather not bog these forums down with redundant posts, I know the work load that gives you guys.

Anyway, thanks for your time.

Edit: Also, I want it so the character only rotates around the Y-Axis, so left-right.

After several work-arounds and a few more dents in my keyboard from my head, I found out what was blocking the rotation.

What I hadn’t realized that I had done before, is attached the physics collision controller to a second node and parented it to the node I wanted to rotate(so it was the parent of nHead). In the second round, I didn’t, so the controller was blocking everything from rotating, making a second node, so on and so forth, allowed me to get it back to the way it was.