Rotating a spatial causes... skybox to rotate? [SOLVED]

I have a class called Unit, which extends the Geometry class.

It looks like this:

public class Unit extends Geometry {

    public Unit(AssetManager assetManager, Vector3f position) {
        setLocalTranslation(position.clone());

        //setup model & texture
        mesh = new Box(0.4f, 0.9f, 0.4f);
        material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        material.setColor("Color", new ColorRGBA(0.3f, 0.5f, 1f, 1f));

        //add collider
        RigidBodyControl body = new RigidBodyControl(new CapsuleCollisionShape(0.3f, 1.8f), 75f);
        body.setKinematicSpatial(true);
        addControl(body);

        //add movement control
        addControl(new UnitMovementControl());
    }

}

As you can see, I add a RigidBodyControl with kinematicSpatial enabled.

The UnitMovementControl is just a class that extends AbstractControl:

public class UnitMovementControl extends AbstractControl {

    @Override
    protected void controlUpdate(float tpf) {
        //the code in this method seems to be the cause of the issue
        float rotation = spatial.getLocalRotation().toAngleAxis(Vector3f.UNIT_Y);

        //limit rotation on X and Z axis
        spatial.setLocalRotation(new Quaternion().fromAngles(0, rotation, 0));
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {

    }

}

Here is how I add the unit to the scene:

//create test unit
Unit unit = new Unit(assetManager, new Vector3f(15f, 20f, 15f));
physics.getPhysicsSpace().add(unit);
rootNode.attachChild(unit);

Now, watch:

…what the?

Seems like you must have added something to your skybox (or perhaps have somehow pollute the Quaternion constants, though I don’t see it and anyway the skybox should have it’s own quaternion always.)

Reduce it down to a simple test case so that we can see all of the code.

Random things:
-your rotation is going to be framerate dependent because you don’t multiple by tpf
-a factory method might be better than subclassing Geometry just to get a convenient constructor.

Solved it.

This line, in the UnitMovementControl, apparently modified the Vector3f.UNIT_Y, lol :smiley:

float rotation = spatial.getLocalRotation().toAngleAxis(Vector3f.UNIT_Y.clone());

Yes, that’s not working like you think it does anyway.

You aren’t asking “how much does this rotate around the Y-axis?” You are asking “how much does this rotate around some arbitrary axis?”… and it’s storing that axis in the target vector provided.

If you want to know how much it’s rotated around the y axis, you have to check the second value of toAngles().

Ok, I see, thanks. I haven’t tried doing what I actually wanted to do yet.

Basically I want to force the RigidBody to never rotate on X and Z (like a character usually does) but allow rotation around the Y axis of course.