- Home /
Optamize player destruction
In my game the player shoots zombies, which are very block like, which I rigged up for their heads to have 16 separate cubes so I can explode them. As of now I spawn the zombies in as a single mesh, and upon getting shot I disable the single mesh, and activate the 16 separate cubes that make up the head. Each cube has a box collider and a rigidbody attached to it. When the bock is shot it gets the rigidbody component and adds a velocity, then destroys that block a couple seconds later. All the blocks use the same texture, but when there is a group of 10 or more zombies, all getting shot up, it dips down to as low as 15fps. My PC is a pretty high end gaming computer, so I know I need to improve upon this. Any suggestions would be appreciated, thanks.
Are you doing something significant in your scripts on collision?
160 cubes isn't much in the grand scheme of things...
@FlyingHighUp Ya I thought that too, for colliders all I have is a box collider on each object. And this is my script:
public void blowChunk (GameObject chunk) {
if (!shot) {
for (int i = 0; i < destructParts.Length; i++) {
destructParts [i].SetActive (true);
}
skinned$$anonymous$$esh.SetActive (false);
headColleder.SetActive (false);
shot = true;
} else {
chunk.transform.SetParent (null);
chunk.GetComponent<Rigidbody> ().is$$anonymous$$inematic = false;
float _velocityX = Random.Range (-500, 500);
float _velocityY = Random.Range (-500, 500);
float _velocityZ = Random.Range (-500, 500);
chunk.GetComponent<Rigidbody> ().AddForce (_velocityX, _velocityY, _velocityZ);
StartCoroutine (destroyChuncks (chunk));
}
}
IEnumerator destroyChuncks (GameObject _chunk) {
yield return new WaitForSeconds (1f);
Destroy (_chunk);
}
Try using a particle system with 3D particles. You can save on GC operations this way as well if you use a single particle system and Susan the cubes at the zombie's head