- Home /
combining meshes
so im working on a tornado game right now, and at the moment the tornado relies on objects in its rotation to destroy other objects. my buildings are made up of hundreds of pices that are held together and held in place so the wont move.i have a s script (downbelow) that when an object hits say the roof with a certian amount of force the roof is replaced with a version of the broken pices not held together, making a shatter effect. the problem is that each individual pice has a mesh collider that will cause the reaction if hit with a certian amount of force. so when the tornado hits the house with hundreds of pices of debrisflying around it, say 2 objects hit the house at the same time the house will clone twice so that there is double the debris. ive had times where it has cloned as many as 7 times which creates insain lag and is way unrealistic. my initial idea was to start with a house that is one pice so then clones into a shattered pice but that didnt really work. i was wondering if there was a way to combine the shattered pices into one mesh so multiple meshes cant be hit at the same time spawning multiple clones. btw i made the house from blender and it is a bit complex. here is the code i use.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class destructible : MonoBehaviour {
public GameObject debrisPrefab;
public float strength;
void OnMouseDown() {
DestroyMe ();
}
void OnCollisionEnter(Collision collision ) {
if (collision.impactForceSum.magnitude > strength) {
DestroyMe ();
}
}
void DestroyMe () {
if (debrisPrefab) {
Instantiate (debrisPrefab, transform.position, transform.rotation);
}
Destroy (gameObject);
}
}