Hi!
In my game you control a ship that can fire at enemy ships, thus destroying them. When the bullet hits the enemy it is destroyed in code, and instanciates an explosion particle effect. The bullet, upon impact is also destroyed.
So far, so good but the problem is that if I fire another bullet that ‘hits’ before the particle effect is done playing it bounces off.
I have tried removing the particle effect and then It works the way I want it so I suspect it’s because the bullet collides with the particles collider? If so, how can i disable the particles collider? or should/must I use the collision matrix?
My code looks like this:
The bullet
if (Input.GetKeyDown (KeyCode.Space))
{
TEMProtation = new Vector3 (90, 0, 0);
bulletStart = new Vector3 (myTransform.position.x, myTransform.position.y, myTransform.position.z + 1); //bullet spawnPos
bulletClone = spawn.ExSpawnObject(bullet,bulletStart,Quaternion.Euler(TEMProtation));
}
The collision:
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "enemy")
{
Destroy (col.gameObject);
Destroy (this.gameObject);
}
}
The particle effect is instantiated from the enemies OnDisable() event:
public void OnDisable()
{
spawn.SpawnObject (explosionPrefab, myTransform.position, Quaternion.identity);
sound.PlaySound (4);
}
heres a youtube video of my solution: https://www.youtube.com/watch?v=OKO3ef6eN8M
– memblock