How do I detect collision between colliders?

I’ve tried to searching for the answer, but I couldn’t seem to find anything. I need to know how to program it such that my swing animation causes damage. OnTriggerEnter doesn’t seem to do anything, although I’m sure I’m doing it wrong. The “enemy” object has a rigidbody, and its collider is a trigger. Also when I check gravity and it falls through the floor the collision works. But when I run into the enemy with my player, which has a collider, nothing happens. Please help.

Keep in mind that for any collision to take effect, one of the objects needs to have a rigidbody attached to it, not just a collider. Collisions always happen between a rigidbody and a collider.

Next thing to consider, OnTriggerEnter is only called if the collider is marked as “trigger”. Make sure that it is.

1 Like

Thanks for the reply, I have a rigid body and the collider is set as a trigger. When gravity is checked on the rigid body and it falls through the world the collision works, but when i crash into the object with the player nothing happens.

Weird. Pause the game, check that the object with the rigidbody actually touches the trigger collider. Check in all dimensions.

Not sure if you’re saying the player has a collider here, or restating that the enemy has a collider. Can you please clarify what game objects have what components?

You might want to check OnControllerColliderHit.

If you’re using one of the standard asset character controllers, you could try adding an additional collider to the player to check for the collision.

If the script that checks is on the enemy, then ensure that the method signature for OnTriggerEnter takes a Collider, and not a Collision, like OnCollisionEnter does.
CSharp

void OnTriggerEnter(Collider col) {
  // do stuff here
}

void OnCollisionEnter(Collision col) {
  // do stuff here
}

JS

function OnTriggerEnter (col : Collider) {
  // do stuff here
}

function OnCollisionEnter (col: Collision) {
  // do stuff here
}