Simple MoveBehaviour

Hi again,

And Thanks normen, for a quick reply :slight_smile:

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

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 :stuck_out_tongue: (I guess this is due to the fact I’m still doing it wrong :wink: )

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

Hi again,

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

thanks for your help which lead me in the right direction :slight_smile:

  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