# Simple MoveBehaviour

Hi again,

And Thanks normen, for a quick reply

I have a little problem with my moveBehaviourâ€¦

I want my player to move forward on W and Backwards on S.

As well as I want the ability to be able to rotate my player on A and D keys.

The input is working perfectly fineâ€¦ However, there is something wrong with my movement. My model rotates, but I only move Along one Axis and not all 3.

`````` if(name.equals("For")){
Vector3f vec = player.getLocalTranslation();
player.setLocalTranslation(vec.x+value*10,vec.y,vec.z);
}else if(name.equals("Back")){
Vector3f vec = player.getLocalTranslation();
player.setLocalTranslation(vec.x-value*10,vec.y,vec.z);
}else if(name.equals("Left")){
player.rotate(0, value*3, 0);
}else if(name.equals("Right")){
player.rotate(0, -value*3, 0);
}          ``````

Do you have an idea to how I can get this right ?

normally what I would do, would be to set a moveDirection and then rotate the direction in the rotate part, and move along the direction in the move part

Itâ€™s how u said in your last sentence. Translation is relative to the parent coordinate system not the model. So rotating in y and moving in z wonâ€™t move in that direction. So find the new direction vector the model is facing model.getlocalrotation().mult(vector3f.unit_z) and move in that.

Iâ€™m sorry, but Iâ€™m still a little lost :/â€¦

When I try to use it, like you described I get weird results (I guess this is due to the fact Iâ€™m still doing it wrong )

``````   if(name.equals("For")){
Vector3f result = player.getLocalRotation().mult(new Vector3f(0,0,1));
player.setLocalTranslation(result);
}else if(name.equals("Back")){
Vector3f result = player.getLocalRotation().mult(new Vector3f(0,0,-1));
player.setLocalTranslation(result);
}else if(name.equals("Left")){
player.rotate(0, value*3, 0);
}else if(name.equals("Right")){
player.rotate(0, -value*3, 0);
}  ``````

would you be able to show me an example, on how to do it ?

Hi again,

Just wanted to mention that I finaly managed to get it working

``````  if(name.equals("For")){
player.move(player.getLocalRotation().mult(new Vector3f(0,0,speed*tpf)));
}else if(name.equals("Back")){
player.move(player.getLocalRotation().mult(new Vector3f(0,0,-speed*tpf)));
}else if(name.equals("Left")){
player.rotate(0, value*3, 0);
}else if(name.equals("Right")){
player.rotate(0, -value*3, 0);
}  ``````
1 Like