- Home /
How to prevent collider overlap during prefab replacement
The problem
I have a series of cubes, that upon receiving a certain amount of force, break into 8 smaller cubes. This is done via the script below. Unfortunately they seem to overlap only when using the script, not when either original or prebroken. Of course this overlap causing a sudden "explosion" of many cubes.
The Script
public class ReplaceOnForce : MonoBehaviour {
public GameObject Prefab;
public float MagnitudeThreshold = 1f;
void OnCollisionEnter(Collision col) {
if (col.relativeVelocity.magnitude > MagnitudeThreshold) {
Object.Destroy (this.gameObject);
GameObject Fracture = (GameObject)Instantiate (Prefab, transform.position, transform.rotation);
} else {
}
}
}
Images
When using script:
When using pre-broken prefab:
What do you mean by original or prebroken? Those are the only two things I can think of replacing them with.
Your answer
Follow this Question
Related Questions
Two rigidbody's overlap instead of colliding 1 Answer
Applying proper drag and center of mass for a vehicle 1 Answer
When and when not to use kinematic rigidbody? 2 Answers
Raycaste vs trigger Colliders & Rigidbody performance 1 Answer
OnCollisionEnter: collision.gameObject has weird behaviour 0 Answers