- Home /
making bullets disappear when they collide
when by bullets hit the wall they don't disappear, how can i make them disappear on collision? all answers are appreciated. (thanks) ;)
Answer by AliAzin · Sep 16, 2010 at 04:20 PM
you should write something like this on your bullet prefab:
function OnCollisionEnter(){ Destroy(gameObject);
}
Answer by Puddin482 · Dec 20, 2010 at 03:53 AM
If AliAzin's code isn't working, perhaps your bullet object is moving too fast for Unity to pick up the collision, you can try setting the collision detection on your rigidbody to "Continuous Dynamic".
However if you want my two cents as a developer, for bullets or other fast moving projectiles you should use raycasting. But perhaps if you want the bullet to actually travel through the air you can get more complicated with it by raycasting from the old position of your bullet to the new position of your bullet each frame to see if you missed anything during the physics iteration. :) hope this helps!
thanks thats great, AliAzin's is working fine but if i need to ever use faster moving bullets i know were to look :)
Answer by XSSA · Jan 10, 2012 at 08:57 AM
function (OnCollisionEnter) { Destroy(gameObject); } This is how you write it. Has problem though it says to put a ";" at the end of the final line. Which results in another error that says: Expressions in statements must only be executed for their side-effects.