diff --git a/assets/Data/entity/creatures/human.json b/assets/Data/entity/creatures/human.json index 4afddda4..b5cdc0f2 100644 --- a/assets/Data/entity/creatures/human.json +++ b/assets/Data/entity/creatures/human.json @@ -549,7 +549,7 @@ }, "idleData": { "animation": { - "nameFirstPerson" : "Idle", + "nameFirstPerson" : "BindPose", "nameThirdPerson" : "Idle", "priorityCategory" : "IDLE" } diff --git a/assets/Models/creatures/viewmodel.glb b/assets/Models/creatures/viewmodel.glb index 69377b95..bd50013a 100644 Binary files a/assets/Models/creatures/viewmodel.glb and b/assets/Models/creatures/viewmodel.glb differ diff --git a/docs/src/progress/currenttarget.md b/docs/src/progress/currenttarget.md index faac5880..b0aab311 100644 --- a/docs/src/progress/currenttarget.md +++ b/docs/src/progress/currenttarget.md @@ -16,8 +16,6 @@ - Physics thread time exploding -- need to sleep bodies + feedback driven requirements - Item/Equip overhaul (again) - Idle viewmodel does not show hands Add punching/unarmed combat UI spacing and scaling Better skybox @@ -25,7 +23,9 @@ Crouching Model clothing, hair for the human particles, light on sword collision + Looking angle leverages rotators to swing sword at angle (ie if you look up you swing your sword into the sky) Come up with a title for the game and create a title menu for it (ideally with some animation and music) + Item/Equip overhaul (again) Objectives - PVP arena mode initially? - Spawn player at start of a dungeon @@ -36,8 +36,6 @@ Fix light cluster mapping for foliage shader Fix lights not being deleted - Not sending a "light count" var to light calculations, so the data stays in buffer even though it is not being updated - Fix static friction coeff causing player to slide on shallow slopes - - Probably need to look into using capsules and cranking up friction value on said capsule Fix block tree preventing initiating an attack Fix return to title menu synchronization bug diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 3cdb8f91..288e1ded 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -830,6 +830,12 @@ Fix ui audio playing at world origin Snow voxel type Move animation work +(09/22/2024) +Hide viewmodel hands when idle +Autodisabling implementation +Fix static friction coeff causing player to slide on shallow slopes + - Turns out it needed auto disabling logic +Change timescale for test # TODO diff --git a/src/main/java/electrosphere/collision/CollisionBodyCreation.java b/src/main/java/electrosphere/collision/CollisionBodyCreation.java index 8f7fa50b..2ba9b751 100644 --- a/src/main/java/electrosphere/collision/CollisionBodyCreation.java +++ b/src/main/java/electrosphere/collision/CollisionBodyCreation.java @@ -155,6 +155,32 @@ public class CollisionBodyCreation { return collisionEngine.createBoxMass(mass, dims, body, offset, rotation); } + /** + * Sets the mass on the dbody + * @param collisionEngine The collision engine + * @param body The body + * @param mass The mass value + * @param radius The radius of the capsule + * @param length The length of the capsule + * @return The DMass object + */ + public static DMass setCapsuleMass(CollisionEngine collisionEngine, DBody body, double mass, double radius, double length, Vector3d offset, Quaterniond rotation){ + return collisionEngine.createCapsuleMass(mass, radius, length, body, offset, rotation); + } + + /** + * Sets the autodisable flags on the body + * @param collisionEngine The collision engine + * @param body The body + * @param autoDisable true to autodisable, false otherwise + * @param linearThreshold the linear velocity threshold to disable under + * @param angularThreshold the angular velocity threshold to disable under + * @param steps the number of simulation steps below thresholds before autodisable + */ + public static void setAutoDisable(CollisionEngine collisionEngine, DBody body, boolean autoDisable, double linearThreshold, double angularThreshold, int steps){ + collisionEngine.setAutoDisableFlags(body, autoDisable, linearThreshold, angularThreshold, steps); + } + /** * Sets the damping for the body * @param collisionEngine The collision engine diff --git a/src/main/java/electrosphere/collision/CollisionEngine.java b/src/main/java/electrosphere/collision/CollisionEngine.java index ad6f10d4..b4140c98 100644 --- a/src/main/java/electrosphere/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/collision/CollisionEngine.java @@ -61,7 +61,7 @@ import electrosphere.logger.LoggerInterface; public class CollisionEngine { //gravity constant - public static final float GRAVITY_MAGNITUDE = 0.2f; + public static final float GRAVITY_MAGNITUDE = 0.15f; /** * The damping applied to angular velocity @@ -133,7 +133,6 @@ public class CollisionEngine { world = OdeHelper.createWorld(); space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT); world.setGravity(0,-GRAVITY_MAGNITUDE,0); - // world.setAutoDisableFlag(true); // world.setContactMaxCorrectingVel(0.1); // world.setContactSurfaceLayer(0.001); world.setCFM(1e-5); @@ -344,7 +343,20 @@ public class CollisionEngine { } if( - !(bodyPointerMap.get(b1).getType() == Collidable.TYPE_TERRAIN && bodyPointerMap.get(b2).getType() == Collidable.TYPE_TERRAIN) && + !( + bodyPointerMap.get(b1).getType() == Collidable.TYPE_TERRAIN && + ( + bodyPointerMap.get(b2).getType() == Collidable.TYPE_TERRAIN || + !b2.isEnabled() + ) + ) && + !( + bodyPointerMap.get(b2).getType() == Collidable.TYPE_TERRAIN && + ( + bodyPointerMap.get(b1).getType() == Collidable.TYPE_TERRAIN || + !b1.isEnabled() + ) + ) && !(bodyPointerMap.get(b1).getType() == Collidable.TYPE_FOLIAGE_STATIC && bodyPointerMap.get(b2).getType() == Collidable.TYPE_FOLIAGE_STATIC) ){ try { @@ -385,6 +397,24 @@ public class CollisionEngine { continue; } + // // + // //apply shallow slope correction + // if( + // //is terrain + // (c1.getType() == Collidable.TYPE_TERRAIN || c2.getType() == Collidable.TYPE_TERRAIN) && + // (!c1.getType().equals(c2.getType())) && + // contact.geom.normal.length() > 0 + // && + // //force is pointing basically upwards + // PhysicsUtils.odeVecToJomlVec(contact.geom.normal).dot(MathUtils.getUpVector()) > 0.7 + // ){ + // System.out.println(PhysicsUtils.odeVecToJomlVec(contact.geom.normal).dot(MathUtils.getUpVector())); + // if(//force is pointing basically upwards + // PhysicsUtils.odeVecToJomlVec(contact.geom.normal).dot(MathUtils.getUpVector()) > 0.7){ + // contact.geom.normal.set(PhysicsUtils.jomlVecToOdeVec(MathUtils.getUpVector())); + // } + // } + // //add contact to contact group DJoint c = OdeHelper.createContactJoint(world,contactgroup,contact); @@ -801,9 +831,6 @@ public class CollisionEngine { spaceLock.acquireUninterruptibly(); DMass mass = OdeHelper.createMass(); mass.setCylinder(massValue, 2, radius, length); - // mass.setCylinderTotal(massValue, 2, radius, length); - // mass.translate(offset.x, offset.y, offset.z); - // mass.rotate(PhysicsUtils.jomlQuatToOdeMat(rotation)); body.setMass(mass); spaceLock.release(); return mass; @@ -820,14 +847,45 @@ public class CollisionEngine { spaceLock.acquireUninterruptibly(); DMass mass = OdeHelper.createMass(); mass.setBox(massValue, dims.x, dims.y, dims.z); - // mass.setBoxTotal(massValue, dims.x, dims.y, dims.z); - // mass.translate(offset.x, offset.y, offset.z); - // mass.rotate(PhysicsUtils.jomlQuatToOdeMat(rotation)); body.setMass(mass); spaceLock.release(); return mass; } + /** + * Creates a DMass and attaches a body to it + * @param massValue The amount of mass for the object + * @param radius The radius of the capsule + * @param length The length of the capsule + * @param body The DBody to attach the mass to + * @return The DMass + */ + protected DMass createCapsuleMass(double massValue, double radius, double length, DBody body, Vector3d offset, Quaterniond rotation){ + spaceLock.acquireUninterruptibly(); + DMass mass = OdeHelper.createMass(); + mass.setCapsule(massValue, 2, radius, length); + body.setMass(mass); + spaceLock.release(); + return mass; + } + + /** + * Sets the auto disable flags for the body + * @param body The body + * @param autoDisable whether auto disable should be used or not + * @param linearThreshold The linear velocity threshold to disable under + * @param angularThreshold The angular velocity threshold to disable under + * @param steps The number of steps the body must be beneath the threshold before disabling + */ + protected void setAutoDisableFlags(DBody body, boolean autoDisable, double linearThreshold, double angularThreshold, int steps){ + spaceLock.acquireUninterruptibly(); + body.setAutoDisableFlag(autoDisable); + body.setAutoDisableLinearThreshold(0.1); + body.setAutoDisableAngularThreshold(angularThreshold); + body.setAutoDisableSteps(steps); + spaceLock.release(); + } + /** * Sets the damping of the body * @param body The body diff --git a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java index b9477f95..0ab96d1d 100644 --- a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java @@ -25,6 +25,21 @@ import electrosphere.server.datacell.utils.ServerEntityTagUtils; */ public class PhysicsEntityUtils { + /** + * The linear velocity threshold to disable under + */ + static final double LINEAR_THRESHOLD = 0.1; + + /** + * The angular velocity threshold to disable under + */ + static final double ANGULAR_THRESHOLD = 0.1; + + /** + * The number of steps below threshold to disable after + */ + static final int STEP_THRESHOLD = 4; + /** * [CLIENT ONLY] Attaches a collidable template to a given entity * @param rVal The entity @@ -59,6 +74,7 @@ public class PhysicsEntityUtils { new Quaterniond(physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW()) ); } + CollisionBodyCreation.setAutoDisable(Globals.clientSceneWrapper.getCollisionEngine(), rigidBody, true, LINEAR_THRESHOLD, ANGULAR_THRESHOLD, STEP_THRESHOLD); // //set offset from center of entity position @@ -117,6 +133,7 @@ public class PhysicsEntityUtils { new Quaterniond(physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW()) ); } + CollisionBodyCreation.setAutoDisable(Globals.clientSceneWrapper.getCollisionEngine(), rigidBody, true, LINEAR_THRESHOLD, ANGULAR_THRESHOLD, STEP_THRESHOLD); // //set offset from center of entity position @@ -168,8 +185,17 @@ public class PhysicsEntityUtils { Collidable.TYPE_CREATURE_BIT ); if(physicsTemplate.getMass() != null){ - throw new UnsupportedOperationException("todo"); + CollisionBodyCreation.setCapsuleMass( + Globals.clientSceneWrapper.getCollisionEngine(), + rigidBody, + mass, + physicsTemplate.getDimension1(), + physicsTemplate.getDimension2(), + new Vector3d(physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ()), + new Quaterniond(physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW()) + ); } + CollisionBodyCreation.setAutoDisable(Globals.clientSceneWrapper.getCollisionEngine(), rigidBody, true, LINEAR_THRESHOLD, ANGULAR_THRESHOLD, STEP_THRESHOLD); // //set offset from center of entity position @@ -254,6 +280,7 @@ public class PhysicsEntityUtils { new Quaterniond(physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW()) ); } + CollisionBodyCreation.setAutoDisable(realm.getCollisionEngine(), rigidBody, true, LINEAR_THRESHOLD, ANGULAR_THRESHOLD, STEP_THRESHOLD); // //set offset from entity center @@ -313,6 +340,7 @@ public class PhysicsEntityUtils { new Quaterniond(physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW()) ); } + CollisionBodyCreation.setAutoDisable(realm.getCollisionEngine(), rigidBody, true, LINEAR_THRESHOLD, ANGULAR_THRESHOLD, STEP_THRESHOLD); // //set offset from entity center @@ -364,8 +392,17 @@ public class PhysicsEntityUtils { Collidable.TYPE_CREATURE_BIT ); if(physicsTemplate.getMass() != null){ - throw new UnsupportedOperationException("todo"); + CollisionBodyCreation.setCapsuleMass( + realm.getCollisionEngine(), + rigidBody, + mass, + physicsTemplate.getDimension1(), + physicsTemplate.getDimension2(), + new Vector3d(physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ()), + new Quaterniond(physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW()) + ); } + CollisionBodyCreation.setAutoDisable(realm.getCollisionEngine(), rigidBody, true, LINEAR_THRESHOLD, ANGULAR_THRESHOLD, STEP_THRESHOLD); // //set offset from entity center diff --git a/src/test/java/electrosphere/entity/state/attack/ServerAttackTreeTests.java b/src/test/java/electrosphere/entity/state/attack/ServerAttackTreeTests.java index 6bf245d2..60ca12bc 100644 --- a/src/test/java/electrosphere/entity/state/attack/ServerAttackTreeTests.java +++ b/src/test/java/electrosphere/entity/state/attack/ServerAttackTreeTests.java @@ -55,7 +55,7 @@ public class ServerAttackTreeTests extends EntityTestTemplate { serverAttackTree.start(); //wait for the attack to propagate back to the client - TestEngineUtils.simulateFrames(10); + TestEngineUtils.simulateFrames(2); //verify it was started on server assertNotEquals(serverAttackTree.getState(), AttackTreeState.IDLE);