diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index bd04c00c..71335477 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2029,6 +2029,7 @@ Moving data packages around Fix client LOD component re-enabling physics positioning Debug rendering of server physics objects Server LOD component properly attaches physics bodies when the entity comes in range +Fix physics destruction on server via ServerLODComponent diff --git a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java index 0115ea0c..0bda9f13 100644 --- a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java @@ -867,6 +867,24 @@ public class PhysicsEntityUtils { } } + /** + * Destroys the physics attached to an entity without outright destroying the entity + * @param entity The entity + */ + public static void serverDestroyPhysics(Entity entity){ + Realm realm = Globals.serverState.realmManager.getEntityRealm(entity); + if(PhysicsEntityUtils.containsDBody(entity)){ + PhysicsUtils.destroyPhysicsPair( + realm.getCollisionEngine(), + PhysicsEntityUtils.getDBody(entity), + PhysicsEntityUtils.getCollidable(entity) + ); + } + PhysicsEntityUtils.setCollidable(entity, null); + Vector3d entityPos = EntityUtils.getPosition(entity); + ServerEntityUtils.repositionEntity(entity, entityPos); + } + /** * Gets the transform from parent entity position to rigid body * @param entity The entity diff --git a/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java b/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java index 2224453d..d4a22ac0 100644 --- a/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java +++ b/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java @@ -4,7 +4,6 @@ package electrosphere.entity.state.lod; import org.joml.Vector3d; import electrosphere.collision.PhysicsEntityUtils; -import electrosphere.collision.PhysicsUtils; import electrosphere.data.entity.common.CommonEntityType; import electrosphere.engine.Globals; import electrosphere.entity.EntityDataStrings; @@ -71,14 +70,7 @@ public class ServerLODComponent implements BehaviorTree { if(this.lodLevel != LOW_RES){ //make low res this.setLodLevel(LOW_RES); - Realm realm = Globals.serverState.realmManager.getEntityRealm(this.parent); - if(PhysicsEntityUtils.containsDBody(this.parent)){ - PhysicsUtils.destroyPhysicsPair( - realm.getCollisionEngine(), - PhysicsEntityUtils.getDBody(this.parent), - PhysicsEntityUtils.getCollidable(this.parent) - ); - } + PhysicsEntityUtils.serverDestroyPhysics(this.parent); } } }