- Home /
How to Destroy an Object while bullet is colliding it
Hello Everyone,
I am a beginner for Unity and I am keeping on learning JavaScript As a Tutorial Project I started making a racing game which shoots the bullet from the car My project is halfway successful I can move my car I can Shoot I can blend Animations
through some command or functions
but still I cant Destroy the enemy with the bullet
I want to destroy the object while colliding it
So Guys Please help me as faster as you can
Thank you
OnTriggerEnter
That's the basic function you're looking for.
Answer by RockDude · Dec 12, 2011 at 04:44 PM
function OnTriggerEnter (hit : Collider){
if(hit.gameObject.tag == "enemy"){
Destroy(hit.gameObject);
}
}
Add this script to your bullet...I'm not sure will it work, but you should try it.
Note: you'll have to tag you're enemy objects as "enemy" to use what RockDude posted, and your enemy object's colliders will have to have "Is Trigger" set to true (checkbox = checked) in the inspector panel. It should work. Your enemy will simply disappear/die as soon as the bullet hits it, but your bullet will continue onward.
Answer by MrBrownPanties · Aug 24, 2015 at 11:59 AM
@Arshad One thing that might also be the problem is the Fixed Timestep. Make sure its small enough (Edit -> Project Setting -> Time , change it to 0.01). Also make sure the bullet speed is not too big.
Hope it helped. Guy.