Search Unity

Question How do I implement Destructible Objects? (with NetCode)

Discussion in 'Physics for ECS' started by Krooq, Jun 8, 2022.

  1. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    196
    Hi all,

    I've been working on a multiplayer game that will feature a destructible object physics simulation which has been challenging to say the least.

    The general setup I have so far is like this:

    Root Physics Body Ghost (client and server)
    Destructible Primitive 1 (server only)
    Fragment 1 (client only)
    Fragment 2 (client only)
    ...​
    Destructible Primitive 2 (server only)
    Fragment 1 (client only)
    Fragment 2 (client only)
    ...​
    ...​
    The Root is the ghost that moves around doing physics stuff using the primitive child colliders.
    When a Destructible is destroyed it's collider should become inactive on the server and fragments should blast around on the client.

    There are 2 constraints that I'm fighting with:
    1. Network data transfer limits really reduces the number of physics entities (ghosts) you can have
    2. Physics child collider baking makes it hard to "destroy" parts of objects at runtime

    I think this is a decent approach given the network data constraint.
    It means I only have one physics ghost to replicate, all the intense fragmentation physics is done locally to avoid said replication.

    The part I'm really super stuck on how to make part of a compound collider inactive?

    I also want to get some feedback from others that have done similar things.
    How'd you do destructible objects over the network?
    How does the DOTS physics & NetCode teams suggest I do this?