Getting crazy with rotate and move [SOLVED]

Hi, I am new to jmonkey so this is probably an noob question !
In other game engines, you put an object, rotate and translate, so when you translate it, it goes in the direction of the face it is translated.
But in jm3 there is no translate ? When I use the move it just goes to another direction like I didn’t have rotate the object at all. How to rotate and translate the object in the simple way ?
I am just trying to make a 2d game like asteroid where using up you just to forward whatever direction the object is rotated, and left/right just rotate the object.

Some code :smile:
if (up) { spatial.move(0,tpf400,0); }
if (down) { spatial.move(0,tpf
-400,0); }
if (left) { spatial.rotate(0,0,0.005f); }
if (right) { spatial.rotate(0,0,-0.005f); }

Expected : the object moves forward / downward .
Happening: the object just go down / up in the screen dosent matter how its rotated.

Thanks in advance !
wagfeliz

Hey, yeah that will happen.

What you need to do is…

Vector3f forward = player.getLocalRotation().mult(Vector3f.UNIT_Z).mult(spd);
player.move(forward);

player was just a Geometry for me. spd is a float, 0 unless you’re pressing up or down in which case it becomes -0.5 and 0.5 respectively.

On a side note, I got this answer really quickly by just searching the forum for the other million times it came up :stuck_out_tongue:

Hi Friend, thanks it works !
I had to use Vector3f.UNIT_X instead thought, its a bit confuse for me yet, but its working :slight_smile:

That’s because your model looks down the x axis instead of the z axis. JME treats the Z axis as “forward” by convention so most advice will be based on that.