having problems with OnControllerColliderHit

i am converting my scripts from my rigidbody controller to a characterController and when translating my onCollisionEnter function to onControllerColliderHit i am having some problems.

my code:

function OnControllerColliderHit (hit : ControllerColliderHit) {
   if (hit.collider.CompareTag("be")) {
      Debug.Log("it works");
      health = health - 1;
	  Destroy(hit.gameObject);
   }
   if (hit.collider.CompareTag("bbe")) {
      health = health - 5;
	  Destroy(hit.gameObject);
   }
}

i put a Debug.Log() in there before the first if and it was registering collisions. the problem is the “if (hit.collider.CompareTag(“be”)) { }” doesnt work. i moved the Debug.Log() into the if and i got nothing from it. am i doing something wrong?

Does the function trigger at least ? → Add Debug.Log (“Function triggering.”);

If it is the case, why doesn’t it work ? What is the tag of the object ? > Add Debug.Log (“Game object tag:” + hit.gameObject.tag);

I know you already used some Debug.Log, in order to debug, but do it again please. :wink:

good idea let me try that

Game object tag:Untagged
UnityEngine.Debug:Log(Object)

which is odd cause the objects i am getting hit with ARE tagged and i can check that in the inspecter.

ok its picking up collision from the terrain how do i fix this.

I’m also having the same problem. Mine’s worse. The debug didn’t even appear. Sigh. The script below is attached to an invisible sphere and when i click the sphere, it will instantiate a cube with “Respawn” tag. But nothing seems to happen. Can anyone help?

function OnCollisionEnter(collision : Collision)
{ 
    if (collision.gameObject.tag == "Respawn") {
     Debug.Log ("Function triggering."); 
       GetComponent(clickSphere).enabled = true;
	  
    } 
}

i dont exactly get what your script does exactly. as for the onCollisionEnter function it is triggered when an object that has a collider and a rigidbody collides with another object with a collider and rigidbody. it is important that both object have both components for it to be triggered.

as for me i would prefer to use onCollisionEnter but instead of a rigidbody i have a characterController so i cant

In fact, only the moving object require a rigidbody. If both object are moving, yes, both will require it.

Concerning the terrain, there shouldn’t be any problem, that’s strange. There should be multiple detections.

What if both are stagnent objects? One of them is a waypoint which turns invisible on play mode. Another object is a cube with tag “Respawn”. It will be instantiated when I click onto the terrain from bird’s eye view on play. The waypoint is supposed to detect that a cube was created within it’s collider and activates a script which in my case is “clickSphere”. But everytime i instantiate the cube inside the waypoint’s collider, nothing seems to happen. Both objects have colliders but not rigidbody.

Two game objects with collider but no rigidbody will never trigger OnCollision messages :wink: use OnTriggerEnter instead.

tried that too. ): But it doesn’t work either. What’s happening!! My brains are gonna burst. D:

function OnTriggerEnter(col : Collider)
{ 
    if (col.gameObject.tag == "Respawn") {
     Debug.Log ("Function triggering."); 
       GetComponent(clickSphere).enabled = true;
	  
    } 
}

One game object must have at least a collider trigger, the other must have at least a rigidbody (kinematic do not matter). Is it the case ?

OMG! it worked!!! How dumb can I be?! Arghs!!! Really thanks… But Anyway, any idea why the cubes that are instantiated within the collider floats rather then being flat on the ground?

Sorry if i sounded confusing. The picture below is what i’m talking about. Cubes instantiated within the collider is floating but cubes outside the collider are flat on the ground.

http://unity3d.com/support/documentation/Manual/Physics.html

I don’t know, is the sphere a sphere collider ?
What are the cubes ? Rigidbody with box collider ?

aaaahhhh quit taking over my thread. i am trying to get help with the OnControllerColliderHit function not the conCollisionEnter function

The problem is that, in the Unity Game Development Essential, you learn to make a camp fire with a collider. The player there has a character controller. Even if it is touching (of course) the ground, it still manage to trigger the collider…I am racking my brain but I can’t manage to find a good idea… :?

i found a solution. i made the bullets triggers.

by bullets, do you mean very fast moving / translating gameobjects …?

yes but it worked with OnCollisionEnter back when i was using a ridigbody controller to make things like that easier. when i started making it multiplayer since i didnt want to make the rigidbody controller script multiplayer i used a charactercontroller controller and had to change a few things

What is the speed of the bullets ? The radius of the CharacterController ? The size of the previous collider associated with the rigidbody ?