- Home /
Remaining bullets ridgidbody bounses of after the enemy has been destroyed.
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);
}
Answer by MarshallN · Feb 09, 2017 at 07:15 PM
Check your explosionPrefab to make sure it doesn't have a collider, first.
Also, are you sure you want your bullet to have a RigidBody? If you just have a collider on it and have it be a trigger, it would pass through any object that doesn't destroy it by default.
Answer by memblock · Feb 09, 2017 at 07:15 PM
I think I solved this. The particle itself has a script attached called "Explosion physics force" Which seems to add force to the rigidbody. I disabled it, and now it works.
heres a youtube video of my solution: https://www.youtube.com/watch?v=O$$anonymous$$O3ef6eN8$$anonymous$$
Your answer
Follow this Question
Related Questions
Is it possible to make a particle system solid??? 2 Answers
make particles move in world space 1 Answer
Can you change the Velocity Over Lifetime of a Particle System using a Script? 3 Answers
how to make bag filled with water that can be moved by physics? 0 Answers
Shuriken particle System - change velocity by trigger 0 Answers