- Home /
C# OnCollisionEnter() problem
I am doing a FPS game. I use a gun and a gun script which shoots physical and raycast bullets. Although OnCollsionEnter() is properly set in the enemy health script , when a bullet is shot it doesn't detect it. but when the player collides with the enemy , it detects it.. So just want to know what I should do.. Should i set a tag to the bullet..? How can I do it ?? There are 3 scripts Gun.cs Health.cs Bullet.cs
I am a noob to Unity.. Please enlighten me ! Thank You !!!
health.cs
void OnCollisionEnter(Collision col) {
if(col.gameObject.tag == "Player")
{
DestroyObject(gameObject);
}
}
Fast moving projectiles generally require very long raycasts. Specifically, it should be at least as many units long as the magnitude of the bullet's forward velocity. Note that you should not expect fast projectiles to be handled by anything but raycasts. Without knowing more about your attempts, this is the best advice I could think of.
So u suggest to speed up the bullet and also its maximize it impact force ??
No, I didn't suggest either of those things. Please review my comment carefully.
Small, fast-moving objects can pass through other objects without triggering a response, because the physics system works with discrete frames. Therefore most "bullet" type objects should be handled exclusively by raycasting. There are numerous articles and posts about this issue if you search for similar problems.
Without knowing more about what you're attempting and how, I can't give better advice.
Your answer
Follow this Question
Related Questions
OnCollisonEnter never being called 1 Answer
bullets don't go forward 1 Answer
Showing a dynamic amount of bullets in a Belt/Magazine/Cylinder 0 Answers
The code is giving me errors 1 Answer
Bullet fires before direction change 0 Answers