Prediction: MovePhysicsComponents helper function

This commit is contained in:
mischa 2024-01-24 14:40:01 +01:00
parent ea13dc67f9
commit 8564e88d97
2 changed files with 9 additions and 4 deletions

View File

@ -148,8 +148,7 @@ protected virtual void CreateGhosts()
physicsGhostRigidbody.ghostEnabledCheckInterval = ghostEnabledCheckInterval; physicsGhostRigidbody.ghostEnabledCheckInterval = ghostEnabledCheckInterval;
// move the rigidbody component & all colliders to the physics GameObject // move the rigidbody component & all colliders to the physics GameObject
PredictionUtils.MoveRigidbody(gameObject, physicsCopy); PredictionUtils.MovePhysicsComponents(gameObject, physicsCopy);
PredictionUtils.MoveAllColliders(gameObject, physicsCopy);
// show ghost by copying all renderers / materials with ghost material applied // show ghost by copying all renderers / materials with ghost material applied
if (showGhost) if (showGhost)
@ -182,8 +181,7 @@ protected virtual void DestroyCopies()
// otherwise next time they wouldn't have a collider anymore. // otherwise next time they wouldn't have a collider anymore.
if (physicsCopy != null) if (physicsCopy != null)
{ {
PredictionUtils.MoveRigidbody(physicsCopy, gameObject); PredictionUtils.MovePhysicsComponents(physicsCopy, gameObject);
PredictionUtils.MoveAllColliders(physicsCopy, gameObject);
Destroy(physicsCopy); Destroy(physicsCopy);
} }

View File

@ -142,5 +142,12 @@ public static void MoveAllColliders(GameObject source, GameObject destination)
MoveCapsuleColliders(source, destination); MoveCapsuleColliders(source, destination);
MoveMeshColliders(source, destination); MoveMeshColliders(source, destination);
} }
// move all physics components from one GameObject to another.
public static void MovePhysicsComponents(GameObject source, GameObject destination)
{
MoveRigidbody(source, destination);
MoveAllColliders(source, destination);
}
} }
} }