- Home /
Rigidbodies violently repel when replacing with pre-shattered opject
Intro
Working on a semi-realistic destruction simulation and was doing some initial testing. I 'm attempting to require a certain amount of force before an object breaks. The nature of the simulation would require multiple objects all colliding with each other.
The Problem
A cube is set to instantiate a "cut up" version of itself upon receiving a certain amount of force (mimicking weaknesses in materials. The code to achieve this is given below:
void OnCollisionEnter(Collision collision) {
if (collision.relativeVelocity.magnitude > MagnitudeThreshold) {
Object.Destroy (this.gameObject);
GameObject Fracture = (GameObject)Instantiate (Prefab, transform.position, transform.rotation);
} else {
}
On it's own the cube breaks as expected, but when multiple "breakable" cubes are stacked and the bottom cube is removed a large "explosion" occurs - not very realistic (shown bottom image). When the "broken" prefab versions of the cubes are arranged identically they behave as expected, as shown top image.
Answer by Akusan · Sep 06, 2017 at 04:14 PM
When you instantiated your prefab pieces, then their collider overlap which cause the violent explosion. Add a script to prevent the overlap when instantiating.
Another thing you could do is say that it's a feature and not a bug.
Answer by rogue6800 · Sep 06, 2017 at 04:48 PM
After some fiddling I finally worked it out for myself. In the physics project settings I enable Adaptive Force and ramped up the Default Solver Velocity Iterations. This resulted in a much better collsion detecting and far more realistic results.
I'll wait to see if someone has a better solution before marking the best answer.
Your answer
Follow this Question
Related Questions
Removing A Component From An Instantiated Prefab After X More Are Instantiated 1 Answer
Instantiated prefab doesn't collide with player 0 Answers
Prefab always spawns with the wrong orientation 2 Answers
how to call the animation of prefab 0 Answers
Using Physics.OverlapBox to get prefabs from found colliders? 0 Answers