Getting mass on object?

Hello, I want to make a bridge that is breaking when the mass of all objects on the bridge are bigger then a specific value.

I know that i can use rigidbody.mass to get the mass of an object.

But how can I calculate the mass off all objects that collide with the bridge?

Thanks alot.

Beautiful question! You could make it as easy as a trigger collider and add the mass OnTriggerEnter() from the entering object, then subtract OnTriggerExit().

When the combined mass > breaking point you switch the bridge to the broken pieces (where rigidbodies could make a fine appearance).

You could also combine y-velocity and mass, where an object of great mass and velocity in the downwards vector would destroy the bridge. Here you could use OnCollisionEnter()/OnCollisionExit() for the bridge but you would have to have continuous calculation of all objects mass/velocity running in an Update or invoked function.

Another approach is to directly use OnCollisionStay() where you continuously calculate the new colliding objects and if they change their appearance in velocity (or perhaps mass) you update their particular reference in an array preferably. To go real professional on this you would also want to add a mass variable towards underlying objects (stacked objects) where the object on top will send its mass down to the next and add to that, the final object will then add the multiplied mass to the bridge.

So basically: Object 1 stands on object 2, object 2 stands on the bridge. Object 1 sends down its mass to object 2, object 2 sends down the combined mass to the bridge. This would be a fine framework for destroying any type of object that has a much to heavy load above. Each object would have a giver variable and a receiver variable for passing masses towards colliding objects below. Here you'd also have to check if the object really is beneath, this can be done with comparing the y-values, a raycast or have a trigger-collider just below the object.