First person "jetPack" fix in HelloCollision.java

I’m a new converter to the jME, using it in my free time. I started with jME2(b/c of more 3d format support) for a while but after learning more about the API and the desire to do physics integration in my game I decided to make the switch to jME3. Anyways. . . Using the HelloCollision file as a test I began tweaking the movement for my First Person Shooter Character. I found out after some testing that when you do a jump, you can continue to move in the direction the camera’s looking. So looking down at the ground and holding down the S (back) key while you Jump makes you continually shoot up in the air ( hence: “jet pack” )until you let go or change directions. (The same goes for the W (forward) key press, but it’s hard to see without anything above.)



I tried to use a method called set [java]setMaxJumpHeight()[/java] i found in jME3 javadoc, but apparently it has been taken out of the nightly build I’m using.

So i figured out a simple fix, for any other newbies out there like myself having trouble with this. . .



I’m trying to do a first person shooter so if that is your goal try it out and see if if helps you out!

After the fix, when you jump in the air forward and backward movement, only works in the default plane so when aiming up or down you don’t fly up in the air, or move fast towards the ground.



In the HelloCollision tutorial for jME3, in the [java]simpleUpdate()[/java] method change the following . . .



[java]public void simpleUpdate(float tpf) {



// This is the default cameraDirection when you first start the game

Vector3f startCam = new Vector3f(0.0f, 0.0f, 0.6f);



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

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



// jump cam same as camDir, except locks the Y axis to one plane

Vector3f jumpCam = new Vector3f(camDir.x, startCam.y, camDir.z);

walkDirection.set(0,0,0);



// If player is on ground do normal movement, else lock Y using jumpCam

if(player.onGround()) {

if (left) { walkDirection.addLocal(camLeft); }

if (right) { walkDirection.addLocal(camLeft.negate()); }

if (up) { walkDirection.addLocal(camDir); }

if (down) { walkDirection.addLocal(camDir.negate()); }

player.setWalkDirection(walkDirection);

cam.setLocation(player.getLocalTranslation());

} else {

if (left) { walkDirection.addLocal(camLeft); }

if (right) { walkDirection.addLocal(camLeft.negate()); }

if (up) { walkDirection.addLocal(jumpCam); }

if (down) { walkDirection.addLocal(jumpCam.negate()); }

player.setWalkDirection(walkDirection);

cam.setLocation(player.getLocalTranslation());

}

}[/java]



Hopeully someone else finds this useful. Any comments or recommendations would be appreciated.



Jared

2 Likes

thank you, I’ve created a firstpersonplayer class that extends PhysicsCharacterNode and takes away all the code for navigating,…

this was a quick and handy fix to not make the user able to fly

Cool. Glad it was useful. It seems to work pretty well when moving and turning in the air and staying parallel to the ground. Unfortunately i think my awesome “jetpack” nickname is keeping some dudes from finding my post. . . Thanks for your reply

It seems that whenever I jump, I can’t move forward?