- Home /
C# Problems with collision
Hi, I've been looking around and I can't seem to figure out why this is not working.
I have two prefabs, a bullet and an enemy. I instantiate them and I want to detect the collision between the two. They both have a RigidBody and an active Collider.
Bullet - Is not a trigger Enemy - IsTrigger and contains the code:
void OnCollisionEnter (Collision otherObject)
{
print("hit");
}
What's confusing me, is that collision is detected when the enemy hits the player, even though the player doesn't have a rigidbody. I'm guessing it's something to do with how I'm spawning the two objects. They are both instantied using similuar code:
Rigidbody clone = Instantiate(bullet, new Vector3(transform.position.x+1, transform.position.y, transform.position.z), transform.rotation) as Rigidbody;
If it's a collision involving a Trigger then you need to use OnTriggerEnter(Collider)
I had tried that earlier but it didn't work. However, I must've changed my setup when fiddling with things and it now works :) Thanks, if you want to write it as an answer I'll accept it :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613140134im_/https://answers.unity.com/themes/thub/images/avi.jpg)