Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Martin Rohwedder

Member Since 29 Jan 2014
Offline Last Active Oct 17 2014 09:30 AM

#5137413 JME3 - How to roll-move a cube along the game world

Posted by Martin Rohwedder on 08 March 2014 - 03:38 PM

Hi all

 

I have solved the problem by attaching a pivot node to the cube, and then translate the cube according to the pivot point.

 

Normally the rotation is done in the center of the object, which is also the case witht the pivot point, but by translating the object relatively to the pivot point, then I was able to move the center of this rotation to the edge of the cube.

 

I got some good help from this post - http://gamedev.stackexchange.com/questions/71445/how-do-i-make-a-cube-move-by-rolling

 

What I did was the following.

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

Then I could rotate it along to z-axis in the simpleUpdate method.

@Override
public void simpleUpdate(float tpf) {
    //rotate along z-axis
    pivot.rotate(0.0f, 0.0f, -0.001f);
}



PARTNERS