Strafing in FPS using vectors

I have my camera direction as a vector (direction).



I have my view node (view) with the geometry in it.



When the player presses forward, i move the view scene backwards:

[java]direction.negateLocal();

direction.multLocal(WALK_SPEED);

view.setLocalTranslation(view.getLocalTranslation().add(direction));[/java]



And the opposite when the players goes backwards.



But when i press right or left, i can’t seem to strafe normally:

[java] Vector3f strafeRight = new Vector3f(-WALK_SPEED,0,0);

direction.multLocal(strafeRight);

view.setLocalTranslation(view.getLocalTranslation().add(direction));[/java]



It doesn’t do what i think it does. Anyone can help me with this math?



[edit] NVM, got it. For anyone wondering, i simply passed the camera reference istead of the direction vector in my method. That way i could get the cam.getLeft() vector and add it directly to the view.

This will actually strafe left, but if you remove the negateLocal() it will strafe right.

[java]

Vector3f strafeRight = cam.getLeft();

strafeRight.negateLocal();

strafeRight.multLocal(WALK_SPEED);

view.setLocalTranslation(view.getLocalTranslation().add(strafeRight));

[/java]

You should try using the FPS controls that come with JME, they have all of this implemented already and will save you a lot of time.

Why are you moving the scene around the camera and not just moving the camera?

Thanks, i’ll look into that.



I’m moving the scene around the player because i’m trying to do an infinite randomly generated dungeon. I’m trying to move the world around the player in the hopes of avoiding some precision errors, although i’m having more problems trying to get the thing working this way…