- Home /
Collison detection not working?
I'm trying to detect whether or not my player controller is colliding with a game object with a specific tag. Here's my code so far:
//Detect collisions
void OnTriggerEnter (Collider targetObj)
{
Debug.Log("Hit!");
//Detect collisions with body
if (targetObj.gameObject.tag == ("Body"))
{
Debug.Log("Hit Self!");
}
}
This is the collider component for the object I want to detect hits from:
But for whatever reason, this isn't working. I've double-checked, and the gameObjects that I want to detect collision for have the appropriate tag, "Body". I've also tried using regular colliders and triggers as well (triggers are preferred). No collisions are being detected, no matter the gameObject.
Answer by Lexa555 · Oct 23, 2021 at 03:51 PM
Does the player have a rigidbody? If not, add a rigid body to your player. If you don't want the player to be affected by the rigidbody then set isKinematic to true. If this doesn't help try adding rigidbody to your other game object.