diff --git a/src/mygame/Main.java b/src/mygame/Main.java index 82b38a1..3095712 100644 --- a/src/mygame/Main.java +++ b/src/mygame/Main.java @@ -19,7 +19,7 @@ import com.jme3.util.SkyFactory; import com.jme3.water.SimpleWaterProcessor; import com.jme3.water.WaterFilter; import mygame.appstate.RunLevel; -import mygame.control.PlayableCharacter; +import mygame.control.PlayablePhysicsCharacter; public class Main extends SimpleApplication { diff --git a/src/mygame/appstate/RunLevel.java b/src/mygame/appstate/RunLevel.java index 68b1f50..3050c48 100644 --- a/src/mygame/appstate/RunLevel.java +++ b/src/mygame/appstate/RunLevel.java @@ -30,6 +30,7 @@ import com.jme3.util.SkyFactory; import com.jme3.water.WaterFilter; import mygame.Main; import mygame.control.PlayableCharacter; +import mygame.control.PlayablePhysicsCharacter; public class RunLevel extends BaseAppState @@ -72,7 +73,7 @@ public class RunLevel extends BaseAppState Node player = (Node)assetManager.loadModel("Models/Oto/Oto.mesh.xml"); Node playerNode = new Node(); playerNode.attachChild(player); - playerNode.addControl(new PlayableCharacter(4f)); + playerNode.addControl(new PlayableCharacter()); ChaseCamera chaseCam = new ChaseCamera(this.app.getCamera(), player, inputManager); @@ -84,16 +85,8 @@ public class RunLevel extends BaseAppState player.move(0,2.5f,0); player.setLocalScale(0.5f); - BetterCharacterControl playerControl = new BetterCharacterControl(1.5f,4f,10f); - playerNode.addControl(playerControl); + //BetterCharacterControl playerControl = new BetterCharacterControl(1.5f,4f,10f); playerNode.addControl(chaseCam); - playerControl.setJumpForce(new Vector3f(0,200f,0)); - - bulletAppState.getPhysicsSpace().add(playerControl); - bulletAppState.getPhysicsSpace().addAll(playerNode); - - playerControl.setGravity(new Vector3f(0,-40f,0)); - playerControl.warp(new Vector3f(0,10,10)); //System.out.println(world.getChildren()); reflectedScene.attachChild(world); diff --git a/src/mygame/control/PlayableCharacter.java b/src/mygame/control/PlayableCharacter.java index 06e0c31..245a552 100644 --- a/src/mygame/control/PlayableCharacter.java +++ b/src/mygame/control/PlayableCharacter.java @@ -40,15 +40,11 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone boolean strafingLeft = false; boolean strafingRight = false; boolean moving = false; - int waitForGround=0; - long lastJump = System.currentTimeMillis(); - float height; AnimChannel channel; //AnimChannel channel_lowerbody; AnimControl control; - public PlayableCharacter(float height) { - this.height=height; + public PlayableCharacter() { } // empty serialization constructor /** This method is called when the control is added to the spatial, @@ -88,66 +84,48 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone */ @Override protected void controlUpdate(float tpf){ - if (waitForGround<4) { - if (moving) { - if (!channel.getAnimationName().equalsIgnoreCase("Walk")) { - channel.setAnim("Walk"); - channel.setLoopMode(LoopMode.Loop); - } - Vector3f camDir = main.getCamera().getDirection(); camDir.y=0; camDir.normalizeLocal(); - Vector3f camLeftDir = main.getCamera().getLeft(); camLeftDir.y=0; camLeftDir.normalizeLocal(); - - Vector3f walkDirection = new Vector3f(0,0,0); - //spatial.setLocalRotation(new Quaternion().fromAngleAxis(spatial.getControl(ChaseCamera.class).getHorizontalRotation(),Vector3f.UNIT_Y)); - //System.out.println(camDir); - moving=false; - if (strafingLeft) { - walkDirection.addLocal(camLeftDir); - moving=true; - } - if (strafingRight) { - walkDirection.addLocal(camLeftDir.negate()); - moving=true; - } - - if (walkingForward) { - walkDirection.addLocal(camDir); - moving=true; - } - if (walkingBackward) { - walkDirection.addLocal(camDir.negate()); - moving=true; - } - - if (moving) { - walkDirection.multLocal(speed).multLocal(tpf); - spatial.getControl(BetterCharacterControl.class).setViewDirection(walkDirection); - spatial.getControl(BetterCharacterControl.class).setWalkDirection(walkDirection); - Vector3f vel = spatial.getControl(BetterCharacterControl.class).getVelocity(); - if (Math.abs(vel.x)<0.1f && Math.abs(vel.y)<0.1f && Math.abs(vel.z)<0.1f) { - System.out.println("Not moving!!"); - waitForGround++; - } else { - waitForGround=0; - } - } else { - channel.setAnim("stand"); - channel.setLoopMode(LoopMode.DontLoop); - spatial.getControl(BetterCharacterControl.class).setWalkDirection(walkDirection); - } + if (moving) { + if (!channel.getAnimationName().equalsIgnoreCase("Walk")) { + channel.setAnim("Walk"); + channel.setLoopMode(LoopMode.Loop); + } + Vector3f camDir = main.getCamera().getDirection(); camDir.y=0; camDir.normalizeLocal(); + Vector3f camLeftDir = main.getCamera().getLeft(); camLeftDir.y=0; camLeftDir.normalizeLocal(); + + Vector3f walkDirection = new Vector3f(0,0,0); + //spatial.setLocalRotation(new Quaternion().fromAngleAxis(spatial.getControl(ChaseCamera.class).getHorizontalRotation(),Vector3f.UNIT_Y)); + //System.out.println(camDir); + moving=false; + if (strafingLeft) { + walkDirection.addLocal(camLeftDir); + moving=true; + } + if (strafingRight) { + walkDirection.addLocal(camLeftDir.negate()); + moving=true; } - } else { - if (spatial.getControl(BetterCharacterControl.class).isOnGround()) { - waitForGround=0; + + if (walkingForward) { + walkDirection.addLocal(camDir); + moving=true; + } + if (walkingBackward) { + walkDirection.addLocal(camDir.negate()); + moving=true; + } + + if (moving) { + walkDirection.multLocal(speed).multLocal(tpf); } else { - spatial.getControl(BetterCharacterControl.class).setWalkDirection(Vector3f.ZERO); + channel.setAnim("stand"); + channel.setLoopMode(LoopMode.DontLoop); } } } @Override public Control cloneForSpatial(Spatial spatial){ - final PlayableCharacter control = new PlayableCharacter(height); + final PlayableCharacter control = new PlayableCharacter(); /* Optional: use setters to copy userdata into the cloned control */ // control.setIndex(i); // example control.setSpatial(spatial); @@ -156,19 +134,16 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone @Override protected void controlRender(RenderManager rm, ViewPort vp){ - /* Optional: rendering manipulation (for advanced users) */ } @Override public void read(JmeImporter im) throws IOException { super.read(im); - // im.getCapsule(this).read(...); } @Override public void write(JmeExporter ex) throws IOException { super.write(ex); - // ex.getCapsule(this).write(...); } @Override @@ -197,10 +172,6 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone public void onAnalog(String name, float value, float tpf) { switch (name) { case "Jump":{ - if (System.currentTimeMillis()-lastJump>=1000 && spatial.getControl(BetterCharacterControl.class).isOnGround()) { - spatial.getControl(BetterCharacterControl.class).jump(); - lastJump = System.currentTimeMillis(); - } }break; } } @@ -213,23 +184,4 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone @Override public void onAnimChange(AnimControl control, AnimChannel channel, String animName) { } - - private boolean isCollision() { - CollisionResults results = new CollisionResults(); - System.out.println(spatial.getControl(BetterCharacterControl.class).getVelocity()); - Ray ray = new Ray(spatial.getLocalTranslation(), spatial.getControl(BetterCharacterControl.class).getVelocity()); - main.getRootNode().collideWith(ray, results); - List collisions = new ArrayList(); - for (int i=0;i=1000 && spatial.getControl(BetterCharacterControl.class).isOnGround()) { + spatial.getControl(BetterCharacterControl.class).jump(); + lastJump = System.currentTimeMillis(); + } + }break; + } + } + + @Override + public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) { + + } + + @Override + public void onAnimChange(AnimControl control, AnimChannel channel, String animName) { + } + + private boolean isCollision() { + CollisionResults results = new CollisionResults(); + System.out.println(spatial.getControl(BetterCharacterControl.class).getVelocity()); + Ray ray = new Ray(spatial.getLocalTranslation(), spatial.getControl(BetterCharacterControl.class).getVelocity()); + main.getRootNode().collideWith(ray, results); + List collisions = new ArrayList(); + for (int i=0;i