Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Martin Rohwedder

Member Since 29 Jan 2014
Offline Last Active Dec 23 2014 08:53 AM

Posts I've Made

In Topic: JME3 - How to roll-move a cube along the game world

12 March 2014 - 04:04 AM

Nice work.  I did something similar with a coin-like object (nearly flat cylinder) in Unity.  It's a bit simpler since it's round, so it's just a matter of making it rotate towards the direction it wants to go.  Though in my case, I wanted to have it interact with the physics, so I actually gave it an impulse on the opposite edge of the direction it wanted to go.

 

You can see my implementation in action here.

 

Is it possible to see the source code (I also try learn unity), so I can learn some of the basics of your implementation??


In Topic: JME3 - How to roll-move a cube along the game world

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