Question on limiting the Y axis in Vector3f walkDirection / setWalkDirection()

i am having trouble with the slowing down of forward walking speed when looking down toward the floor in 3rd person using chasecamera. i researched the forums and came up with the solution that i have to limit the Y axis of walkDirection so it doesnt try to walk down into the floor (or up) along with forward and backward movement.

my question is how do i do this effectively?

this is a simplified section of my simpleUpdate code where i have commented out the different ways i have attempted to (unsuccessfully) keep this unwanted action from occurring. (taken mainly from walkingChar in the test project)



public void simpleUpdate(float tpf) {

Vector3f camDir = cam.getDirection().clone().multLocal(0.2f);

Vector3f camLeft = cam.getLeft().clone().multLocal(0.2f);

camDir.y = 0;

camLeft.y = 0;

walkDirection.set(0, 0, 0);

if (left) {



if (right) {



if (up) {


//walkDirection.y = 0


if (down) {


//walkDirection.y = 0


//walkDirection.y = 0





i use the camDir vector to set the direction my character faces ensuring i am always facing the same direction as the chasecam minus the up and down, and i believe this has successfully removed the unnecessary Y component from that vector, but i cant seem to eliminate it from my walkDirection Vector.

i am still very new at java and jme3, so any help or criticism will be appreciated.

try this:




should i do this for each of my onAction inputs, or just once after them before applying walkDirection to the characterControl?

and do i need to define the variable speed or was that just a placeholder for illustration?

thx for the speedy reply!

WalkDirection is just a vector determining how far to move when applied. Therefore, if you never want a Y component, just set the Y to zero before setting walkDirection. However, looking at you code above you seem to be combining the direction and the speed before you set the Y to 0.

If you changed your code to:

Vector3f camDir = cam.getDirection().clone();

Vector3f camLeft = cam.getLeft().clone();

camDir.y = 0;

camLeft.y = 0

And then multiplied by the speed (which you may be better off doing on each input so you can move different speeds different directions) you would never have the Y component to worry about in the walk direction anyway.

(I can’t remember if the direction vectors you get back from the camera are normalized. If not also normalize them before using them so you get a consistent movement vector.)

An important thing is that WalkDirection is not a direction, it is a movement vector; i.e. I will add the WalkDirection vector to my current position. You seemed to have grasped this looking at your code above.