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?