From cacc8dc57fac7831fb458cb08a6c65e1359d9adb Mon Sep 17 00:00:00 2001 From: austin Date: Sun, 4 Aug 2024 12:18:06 -0400 Subject: [PATCH] small movement work --- assets/Data/creatures/human.json | 2 + docs/src/progress/renderertodo.md | 5 +++ .../java/electrosphere/engine/Globals.java | 2 +- .../groundmove/ClientGroundMovementTree.java | 9 ++-- .../groundmove/ServerGroundMovementTree.java | 41 +++++++++++++++++-- .../entity/types/creature/CreatureUtils.java | 2 +- .../type/movement/GroundMovementSystem.java | 22 ++++++++++ 7 files changed, 74 insertions(+), 9 deletions(-) diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index df9f956c..8f2386b5 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -129,6 +129,8 @@ "type" : "GROUND", "acceleration" : 5000.0, "maxVelocity" : 500.5, + "strafeMultiplier" : 0.7, + "backpedalMultiplier" : 0.5, "animationStartup" : { "nameThirdPerson" : "Jog", "priorityCategory" : "CORE_MOVEMENT" diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index b7a1eabe..bd3f962f 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -503,6 +503,11 @@ State transition utils interrupt support Block animation cancels immediately on first person model Bone-attachment fix Fix data for viewmodel hand.r equip point +Support audio on state transition +Audio on block state transitions + +(08/04/2024) +Strafe/backpedal movement speed multipliers # TODO diff --git a/src/main/java/electrosphere/engine/Globals.java b/src/main/java/electrosphere/engine/Globals.java index b02ddb50..6bde6a20 100644 --- a/src/main/java/electrosphere/engine/Globals.java +++ b/src/main/java/electrosphere/engine/Globals.java @@ -135,7 +135,7 @@ public class Globals { public static boolean RUN_DEMO = false; public static boolean RUN_CLIENT = true; public static boolean RUN_HIDDEN = false; //glfw session will be created with hidden window - public static boolean RUN_AUDIO = true; + public static boolean RUN_AUDIO = false; public static int clientCharacterID; // diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java index 86b5d3b9..c478fc99 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java @@ -20,7 +20,6 @@ import electrosphere.entity.state.attack.ClientAttackTree.AttackTreeState; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; import electrosphere.entity.state.movement.FallTree; import electrosphere.entity.state.movement.SprintTree; -import electrosphere.entity.state.movement.SprintTree.SprintTreeState; import electrosphere.entity.state.movement.jump.ClientJumpTree; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.synchronization.annotation.SyncedField; @@ -93,7 +92,7 @@ public class ClientGroundMovementTree implements BehaviorTree { GroundMovementSystem groundMovementData; Entity parent; - + Collidable collidable; CopyOnWriteArrayList networkMessageQueue = new CopyOnWriteArrayList(); @@ -112,6 +111,9 @@ public class ClientGroundMovementTree implements BehaviorTree { */ private ClientGroundMovementTree(Entity e, Object ... params){ //Collidable collidable, GroundMovementSystem groundMovementData + if(params.length < 2){ + throw new IllegalArgumentException("Tried to create a client ground movement tree without providing both mandatory parameters"); + } state = MovementTreeState.IDLE; parent = e; this.collidable = (Collidable)params[0]; @@ -188,9 +190,8 @@ public class ClientGroundMovementTree implements BehaviorTree { public void simulate(float deltaTime){ float velocity = CreatureUtils.getVelocity(parent); float acceleration = CreatureUtils.getAcceleration(parent); - float maxNaturalVelocity = sprintTree != null && sprintTree.getState() == SprintTreeState.SPRINTING ? sprintTree.getMaxVelocity() : CreatureUtils.getMaxNaturalVelocity(parent); + float maxNaturalVelocity = ServerGroundMovementTree.getMaximumVelocity(parent, this.groundMovementData, facing); Actor entityActor = EntityUtils.getActor(parent); -// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent)); Vector3d position = EntityUtils.getPosition(parent); Vector3d facingVector = CreatureUtils.getFacingVector(parent); DBody body = PhysicsEntityUtils.getDBody(parent); diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java index 67174257..4afbdec5 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java @@ -14,6 +14,7 @@ import electrosphere.collision.collidable.Collidable; import electrosphere.engine.Globals; import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.game.data.creature.type.movement.GroundMovementSystem; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; @@ -23,7 +24,6 @@ import electrosphere.entity.state.attack.ClientAttackTree.AttackTreeState; import electrosphere.entity.state.attack.ServerAttackTree; import electrosphere.entity.state.movement.ServerFallTree; import electrosphere.entity.state.movement.ServerSprintTree; -import electrosphere.entity.state.movement.ServerSprintTree.SprintTreeState; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementRelativeFacing; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState; import electrosphere.entity.state.movement.jump.ServerJumpTree; @@ -62,6 +62,9 @@ public class ServerGroundMovementTree implements BehaviorTree { MovementTreeState state; @SyncedField MovementRelativeFacing facing; + + //The data for the movement system + GroundMovementSystem groundMovementSystem; ServerSprintTree sprintTree; ServerJumpTree jumpTree; @@ -80,11 +83,12 @@ public class ServerGroundMovementTree implements BehaviorTree { private ServerGroundMovementTree(Entity e, Object ... params){ - //Collidable collidable + //Collidable collidable, GroundMovementSystem system state = MovementTreeState.IDLE; facing = MovementRelativeFacing.FORWARD; parent = e; this.collidable = (Collidable)params[0]; + this.groundMovementSystem = (GroundMovementSystem)params[1]; } public MovementTreeState getState(){ @@ -165,7 +169,7 @@ public class ServerGroundMovementTree implements BehaviorTree { if(CreatureUtils.hasVelocity(parent)){ velocity = CreatureUtils.getVelocity(parent); acceleration = CreatureUtils.getAcceleration(parent); - maxNaturalVelocity = sprintTree != null && sprintTree.getState() == SprintTreeState.SPRINTING ? sprintTree.getMaxVelocity() : CreatureUtils.getMaxNaturalVelocity(parent); + maxNaturalVelocity = ServerGroundMovementTree.getMaximumVelocity(parent, this.groundMovementSystem, facing); } if(ServerPlayerViewDirTree.hasTree(parent)){ ServerPlayerViewDirTree serverViewTree =ServerPlayerViewDirTree.getTree(parent); @@ -471,6 +475,37 @@ public class ServerGroundMovementTree implements BehaviorTree { this.fallTree = fallTree; } + /** + * Gets the maximum velocity of an entity + * @param entity + * @param groundMovementSystem + * @return + */ + public static float getMaximumVelocity(Entity entity, GroundMovementSystem groundMovementSystem, MovementRelativeFacing facing){ + float maxVelocity = groundMovementSystem.getMaxVelocity(); + switch(facing){ + case FORWARD: { + return maxVelocity; + } + case BACKWARD_LEFT: + case BACKWARD_RIGHT: + case BACKWARD: { + if(groundMovementSystem.getBackpedalMultiplier() != null){ + return maxVelocity * groundMovementSystem.getBackpedalMultiplier(); + } + } break; + case LEFT: + case RIGHT: + case FORWARD_LEFT: + case FORWARD_RIGHT: { + if(groundMovementSystem.getStrafeMultiplier() != null){ + return maxVelocity * groundMovementSystem.getStrafeMultiplier(); + } + } break; + } + return maxVelocity; + } + /** *

Automatically generated

*

diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index ebe3bcea..e888a1f7 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -399,7 +399,7 @@ public class CreatureUtils { // Generic ground case GroundMovementSystem.GROUND_MOVEMENT_SYSTEM: GroundMovementSystem groundMovementSystem = (GroundMovementSystem)movementSystem; - ServerGroundMovementTree moveTree = ServerGroundMovementTree.attachTree(rVal,CollisionObjUtils.getCollidable(rVal)); + ServerGroundMovementTree moveTree = ServerGroundMovementTree.attachTree(rVal,CollisionObjUtils.getCollidable(rVal),groundMovementSystem); if(groundMovementSystem.getAnimationStartup() != null){ moveTree.setAnimationStartUp(groundMovementSystem.getAnimationStartup().getNameThirdPerson()); } diff --git a/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java b/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java index c788cf7f..e51806a3 100644 --- a/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java @@ -18,6 +18,12 @@ public class GroundMovementSystem implements MovementSystem { float acceleration; float maxVelocity; + //The multiplier for movement speed when strafing + Float strafeMultiplier; + + //The multiplier for movement speed when backpedaling + Float backpedalMultiplier; + //startup data TreeDataAnimation animationStartup; @@ -79,6 +85,22 @@ public class GroundMovementSystem implements MovementSystem { return sprintSystem; } + /** + * Gets the multiplier applied to the movement speed while the creature is strafing + * @return The multiplier + */ + public Float getStrafeMultiplier(){ + return this.strafeMultiplier; + } + + /** + * Gets the multiplier applied to the movement speed while the creature is backpedaling + * @return The multiplier + */ + public Float getBackpedalMultiplier(){ + return this.backpedalMultiplier; + } + @Override public String getType() { return type;