Shatter effect

Hey there!

I am working on a little shooter game for college and i wanted to create a piece of glass that breaks on collision.
To do that i built an original piece of glass and the same one splattered in many broken pieces with Maya, imported them and put them into prefabs to add some glass material.
I placed one of the original glass pieces in my game and added following code:

public class Destruction : MonoBehaviour {

public GameObject destructionPiece;

void OnCollisionEnter(Collision collision) {

Instantiate (destructionPiece, this.transform.position, this.transform.rotation);
Destroy(gameObject);

}
}

If the Object collides with something it shall be destroyed and instead of it there should be the object with the many glass pieces.

So far so good, everything works, BUT:

The broken glass object appears at another location. I cannot give the two type of prefabs the same parameters. If i give the original one the paramters of the broken one, the first one has the size of a cube.
How could i give the 2nd object the correct location parameters inside of the code?

Thanks for your help!

When you say “appears at another location;” this means to me that the two prefabs have different a different of origin. Both prefabs should have the same XYZ origin and appear in the same location at that origin. I think this would solve your positioning problem.

On a secondary note. Using the shattered glass theory. I would give each shard it’s own object, with its own rigidbody and meshcollider. Add force from the collision intersection, maybe add motion in a radial pattern from the impact point relative to the velocity of the collision. This of course adds more processing to the game, but it would be a cool effect.

Alternatively, you could not add colliders to it, if it affects game performance.