From 4ff13ec965927ee7a4c7de68a928620fde101d1d Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Mon, 6 Jul 2020 06:23:08 +0900 Subject: [PATCH] Update physics / acceleration to handle horizontal speeds + friction surfaces. --- assets/Scenes/TestLevel.j3o | Bin 92281 -> 92397 bytes build/classes/mygame/Main.class | Bin 5159 -> 5266 bytes src/mygame/camera/CustomChaseCamera.java | 2 +- src/mygame/control/PhysicsControl.java | 71 +++++++++++++++++++++- src/mygame/control/PlayableCharacter.java | 40 ++++++------ 5 files changed, 89 insertions(+), 24 deletions(-) diff --git a/assets/Scenes/TestLevel.j3o b/assets/Scenes/TestLevel.j3o index 65061fd7b9389bac59378c9a2c04c49806f8d78f..fb1b72759b0cc1b91605d3c85ff3cfc0da3823df 100644 GIT binary patch delta 1805 zcmZ{kTWpj?6vyX3-`=~W_r0~H+ivd*6zKNe?m`13Vo60)A*G0=E!~)@zA5K0!9HT6RDf#?Vdet@nFSiEfPT8Z74qN(~!w-8}=Crk2o}-ohBu_aq z%44)as+QQqcr=-?D%mtSmWY~1DLF^t$CK0XSfXztk#whz=6r#kxkl%>HT5HZ{X?L9 ziM%1O(L&zjP%ivwtpCMz<=!nJ@Hly!dOf*7hR8*7id1Ku;J8EmWpY`-f0VpSPLlTo zD&HgT3sm{Z6@gUXFojhPwef*KbvG~JfAuUUkXJ}aE|Qu+O#^8n`$#j%9Kb@pOIpcK zNE`VLX(xXn9maYN9b+JHaxf6&iWF*AC~Od@-9hF(bOia-4^l4>*$7ZbG6EEdYy>P; zHUg9gr~u$H_PGV>Tc~@C0K7&3K02TrF6Hm%$uja+vOFcgfan&<%TYlkM*5BQO43ig zibHuEpw5(|nv9b*BvXxA@=dZ%VCOhlPrgVtkY~w8@_jN$eoSs6KPOY0DSS_13;7$_ zM6!<9D$rX%ZX+wn?PL?#O!kl=av#}39wJ-G39?OK&!=R&z}^qY4uO6X*(tDJ^-q_P znQnn6qik37sMMq#uAL?`-^xqCeEO&4GG;m$whK5@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i4;FfjNOx0YDOLK*$YQJDT#4D!tYOWMUa;2?I7Kye)Ey{~9u!&+td43Zm zifX!vQ5sTm34?-xH4LuC8)#v0t%xC`do5>Zt*VvC82V0fv@nfKrpw{Ykb}Ecj%=nJ z)eQ&P6c8sbrb|SooY)LGMY|eB@^ZRpOC|;PUL4KLy>!-Gw+ElSKlvqTMLSfq-Py$G z@4+xdUL(WXW|SkFO_2?=@j{ex>#D{ gNRB&18`1OdWsxYxJ>sy*!=l@XzE5-maxSpd) { + hspd -= acceleration*tpf; + } else { + hspd = -maxSpd; + } + } + } + + float getHorizontalSpeed() { + return hspd; + } + boolean isOnGround() { if (vspd>0) { //System.out.println(vspd); @@ -137,6 +205,7 @@ public class PhysicsControl extends AbstractControl implements Savable, Cloneabl //System.out.println(newResults.getClosestCollision()); if (newResults.getClosestCollision().getDistance()<=(modelHeight/2)+0.1-vspd) { spatial.setLocalTranslation(newResults.getClosestCollision().getContactPoint()); + standingOn = newResults.getClosestCollision().getGeometry(); return true; } else { return false; diff --git a/src/mygame/control/PlayableCharacter.java b/src/mygame/control/PlayableCharacter.java index 60ec6a5..252494d 100644 --- a/src/mygame/control/PlayableCharacter.java +++ b/src/mygame/control/PlayableCharacter.java @@ -52,7 +52,7 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone AnimControl control; PhysicsControl physics; - Vector3f walkDirection; + Vector3f walkDirection = Vector3f.ZERO.clone(); float lastActionPerformed = 0.0f; static final float FREECAMERATIME = 0.5f; @@ -115,7 +115,15 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone /*if (this instanceof NetworkPlayableCharacter) { System.out.println("1:"+getWalkDirection()+"Moving:"+moving+"/"+strafingLeft+"/"+strafingRight+"/"+walkingBackward+"/"+walkingForward); }*/ - main.getCamera().setLocation(spatial.getLocalTranslation().add(-20,7f,0)); + //main.getCamera().setLocation(spatial.getLocalTranslation().add(-20,7f,0)); + if (physics.getHorizontalSpeed()!=0.0f) { + SmoothMoveWalk(walkDirection, tpf); + //Message msg = new PlayerPositionMessage(spatial.getLocalTranslation()); + //main.client.send(msg); + } else { + channel.setAnim("stand"); + channel.setLoopMode(LoopMode.DontLoop); + } if (moving) { if (!(this instanceof NetworkPlayableCharacter)) { cameraTransition+=tpf*4; @@ -129,22 +137,10 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone moving=false; - if (this instanceof NetworkPlayableCharacter) { - walkDirection = getWalkDirection((Vector3f)spatial.getUserData("lastCamDir"),(Vector3f)spatial.getUserData("lastCamLeftDir")); - } else { - walkDirection = getWalkDirection(main.getCamera().getDirection(),main.getCamera().getLeft()); - } + walkDirection = getWalkDirection(tpf); /*if (this instanceof NetworkPlayableCharacter) { System.out.println(" 2:"+getWalkDirection()+"Moving:"+moving+"/"+strafingLeft+"/"+strafingRight+"/"+walkingBackward+"/"+walkingForward); }*/ - if (moving) { - SmoothMoveWalk(walkDirection, tpf); - //Message msg = new PlayerPositionMessage(spatial.getLocalTranslation()); - //main.client.send(msg); - } else { - channel.setAnim("stand"); - channel.setLoopMode(LoopMode.DontLoop); - } } else { if (!(this instanceof NetworkPlayableCharacter)) { //System.out.println(spatial.getControl(CustomChaseCamera.class).getHorizontalRotation()+","+(spatial.getControl(CustomChaseCamera.class).getHorizontalRotation()%(2*Math.PI))); @@ -269,18 +265,18 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone public void onAnimChange(AnimControl control, AnimChannel channel, String animName) { } - public Vector3f getWalkDirection(Vector3f camDir, Vector3f camLeftDir) { - camDir.y=0; camDir.normalizeLocal(); - camLeftDir.y=0; camLeftDir.normalizeLocal(); - - Vector3f walkDirection = new Vector3f(0,0,0); + public Vector3f getWalkDirection(float tpf) { if (strafingLeft) { - walkDirection.addLocal(0,0,-1); + this.walkDirection.setZ(-1); + //physics.setHorizontalSpeed(-speed); + physics.accelerate(false, tpf); moving=true; } if (strafingRight) { - walkDirection.addLocal(0,0,1); + this.walkDirection.setZ(1); + //physics.setHorizontalSpeed(speed); + physics.accelerate(true, tpf); moving=true; }