Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Martin Rohwedder   Members   -  Reputation: 180

Like
0Likes
Like

Posted 06 March 2014 - 04:26 AM

Hi all

I am trying jMonkeyEngine out and is trying to learn how to make some small games with it. I am having a problem. I have a simple rectangular cube which is my intention that the player should be able to roll around the gameworld.

When he presses the arrow keys the cube should make a roll towards the way the user pressed the array key, so if he presses the right arrow key, the cube rolls 1 WU to the right.

The problem is not to move the cube, which I can du with the move() method, but my problem is how I 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 this game - https://www.youtube.com/watch?v=aml5FoyyKLo

 

Hopes anyone can help me :)



Sponsor:

#2 TheChubu   Crossbones+   -  Reputation: 4548

Like
0Likes
Like

Posted 06 March 2014 - 06:51 AM

Afaik jMonkeyEngine has a physics system based on jBullte, so I'm guessing you'd need to set up the cube so the key presses apply an impulse on it to flip it around.

 

I haven't seen anyone here using JME, you might want to check their own forums.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#3 krinosx   Members   -  Reputation: 550

Like
0Likes
Like

Posted 06 March 2014 - 07:56 AM

Check this tutorial in JME3 forum:

 

http://hub.jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_input_system

 

It show you how to use input system to move your player around:

        if (name.equals("Rotate")) {
          player.rotate(0, value*speed, 0);
        }
        if (name.equals("Right")) {
          Vector3f v = player.getLocalTranslation();
          player.setLocalTranslation(v.x + value*speed, v.y, v.z);
        }
        if (name.equals("Left")) {
          Vector3f v = player.getLocalTranslation();
          player.setLocalTranslation(v.x - value*speed, v.y, v.z);
        }

If you see the full source, you will realize that 'player' is a instance of Geometry class... you can use methods from Geometry class to deal with positioning, rotations, etc...

 

So you may use your 'cube' as a instance of geometry or some derived class and use the same approach if you don't intend to use physics engine.

 

Hope it helps... btw... JME3 has a lot of tutorials here: http://hub.jmonkeyengine.org/wiki/doku.php/jme3

 

Try to play with it and see what you can get....

 

[]´s



#4 Doublefris   Members   -  Reputation: 316

Like
0Likes
Like

Posted 06 March 2014 - 06:06 PM

You could do something like, each frame find the closest edge of the cube to the ground along the velocity vector. then rotate the cube along this line.



#5 Martin Rohwedder   Members   -  Reputation: 180

Like
1Likes
Like

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


#6 ferrous   Members   -  Reputation: 2071

Like
1Likes
Like

Posted 10 March 2014 - 03:24 PM

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.



#7 Martin Rohwedder   Members   -  Reputation: 180

Like
0Likes
Like

Posted 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??



#8 ferrous   Members   -  Reputation: 2071

Like
0Likes
Like

Posted 13 March 2014 - 06:50 PM

 

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

 

Sure, for the coins, I forgot that was actually my first implementation, I found it to be more reliable to instead just add torque.

if( (Time.fixedTime - prevFlipTime) > TimeBetweenFlips && isTouchingGround)
{
    Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
    this.rigidbody.AddTorque(FlipForce*Vector3.Cross(Vector3.up, dir));
}
			
		





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS