I am learning jMonkeyEngine by making some small games with it. I have a simple rectangular cube that I want the player to be able to roll around the game world.
When he presses the arrow keys, the cube should make a roll in the direction of the key press. (So, for instance, pressing the right arrow key makes the cube roll 1 WU to the right.)
The problem isn't how to move the cube (I can do that with the move()
method), but with how to make this rotation effect so it doesn’t look like the cube is moving to the destination, but is actually rolling.
The rolling effect should be like the cube in Bloxorz. (Here's a gameplay video.)
UPDATE
After I got some good help below, I have come up with a test solution, which I want to share with you.
Box box1 = new Box(1,1,1);
Geometry boxGeom = new Geometry("Box", box1);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
boxGeom.setMaterial(mat1);
//attach the cube to the pivot node
pivot = new Node("pivot");
pivot.setLocalTranslation(0.0f, 0.0f, 0.0f);
rootNode.attachChild(pivot); // put this node in the scene
pivot.attachChild(boxGeom);
//Translate the box so the pivot node is at the bottom right edge of the box
boxGeom.move(-1.0f, 1.0f, 0.0f);
And then rotate it like this.
@Override
public void simpleUpdate(float tpf) {
//rotate along z-axis
pivot.rotate(0.0f, 0.0f, -0.001f);
}