# Cannot detect collision between objects

**URL:** https://discussions.unity.com/t/cannot-detect-collision-between-objects/91416
**Category:** Questions & Answers
**Created:** [January 2, 2014, 6:23pm UTC](https://discussions.unity.com/t/cannot-detect-collision-between-objects/91416 "2014-01-02T18:23:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hackgamn](https://avatars.discourse-cdn.com/v4/letter/h/779978/32.png) [@hackgamn](https://discussions.unity.com/u/hackgamn)
#### Post date: [January 2, 2014, 6:23pm UTC](https://discussions.unity.com/t/cannot-detect-collision-between-objects/91416/1 "2014-01-02T18:23:20Z")

</div>

Hi, I am making my first game and I do not really understand the collisions. I was trying to detect a collision between my character(charactercontroller) and the enemy’s sword(rigidbody, mesh collider), using oncontrollercolliderhit, but it did not work. Could anyone help me?

```
The character's script 
using UnityEngine;
using System.Collections;

public class PlayerStats : MonoBehaviour {
	
	//public int LVL;
	//public GameObject Target;
	public int MaxHealth; // Максимальное количество здоровья
	public int CurHealth; // Текущее количество здоровья
	public int MaxMana; // Максимально количество маны
	public int CurMana; // Текущее количество маны
	
	public bool AttackStats = false;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if(MaxHealth < CurHealth) CurHealth = MaxHealth;
		if(MaxMana < CurMana) CurMana = MaxMana;
		if(CurHealth < 0) CurHealth = 0;
	}
	 void OnControllerColliderHit(ControllerColliderHit playerCollider){
     if(playerCollider.gameObject.tag == "sword"){
      Debug.Log("Hit Player");
     }
   }
	
	}

```

---

<div class="post-metadata">

### Author: ![BigRoy](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@BigRoy](https://discussions.unity.com/u/BigRoy)
#### Post date: [January 2, 2014, 9:33pm UTC](https://discussions.unity.com/t/cannot-detect-collision-between-objects/91416/2 "2014-01-02T21:33:16Z")

</div>

**The _OnControllerColliderHit()_ method is only called in combination with the Character Controller behaviour component.**

Are you sure the object you’re using contains the CharacterController behaviour component, because the OnControllerColliderHit method is called from that component (not from RigidBody component if I’m correct).

Also see the following links:

[http://forum.unity3d.com/threads/29919-OnCollisionEnter-vs-OnControllerColliderHit](http://forum.unity3d.com/threads/29919-OnCollisionEnter-vs-OnControllerColliderHit)

[http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnControllerColliderHit.html](http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnControllerColliderHit.html)

Put a `Debug.Log("Hit Controller");` directly in the method to see if it’s finding any hit in OnControllerColliderHit() method in general.

**The _OnControllerColliderHit()_ only gets called if the controller is moving at the same time**

Quote from [here](http://answers.unity3d.com/questions/465292/oncontrollercolliderhit-function-is-not-called-if.html):

- _“If you read the docs, that’s how it should work: “OnControllerColliderHit  
is called when the controller hits a  
collider while performing a Move.”  
(emphasis is mine.) If means it only  
checks during CC.Move or  
CC.simpleMove.  
To check for other stuff hitting you when it moves, just use a regular  
OnCollisionEnter.”_ - Owen Reynolds

**You might want to use the _OnCollisionEnter()_ method instead if you always want to find any collision.**

Otherwise you could try putting it in the OnCollisionEnter() method. Like so:

```
void OnCollisionEnter(){
    if(playerCollider.gameObject.tag == "sword"){
        Debug.Log("Hit Player");
    }
}

```
