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?
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
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.
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.
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… :?
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