Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.)


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);

//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


//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.

public void simpleUpdate(float tpf) {
    //rotate along z-axis
    pivot.rotate(0.0f, 0.0f, -0.001f);
share|improve this question
It's totally fine to post your own solution as an answer by the way. Keeps things clear for future readers! – Anko Mar 8 '14 at 22:53
up vote 8 down vote accepted

Conceptually, you can do that by animating the rotation of the cube (or as in Bloxorz, a cuboid) 90 degrees around one of its edges. You don't need move() at all!

Side-on view of one rotation:

side-on perspective of rotation of a cuboid around one of its edges

Here's a seriously good JMonkeyEngine tutorial showing you how to rotate Boxes around pivot Nodes. It explains everything step-by-step. These are the important lines:

/** Create a pivot node at (0,0,0) and attach it to the root node */
Node pivot = new Node("pivot");

/** Attach your cuboid to the *pivot* node. (And transitively to the root node.) */
/** Rotate the pivot node: This rotates everything attached to it! */
pivot.rotate(.4f, .4f, 0f);

Once you've got that, rolling around becomes successive rotations around different pivots:

side-on perspective of two successive rotations

share|improve this answer
Thank you, it seems that using a pivot is a good solution, I din't think of that... Thank you! – Rohwedder Mar 7 '14 at 15:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.