- Home /
increase range of OnControllerColliderHit
I'm using OnControllerColliderHit to trigger an event. I would like to increase the range of the detection from the Character Controller. Is there a way to do this?
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if (hit.gameObject.tag == "the trigger thing")
{
stuff happens;
}
}
In other words, I would like it to behave like:
Physics.Raycast(transform.position, direction, hit, RaycastLength)
Answer by Peter G · Apr 29, 2010 at 10:33 PM
The simplest way would be to increase the radius of the Character Controller. Then by definition, the range of the OnControllerColliderHit() will be further.
If you want to increase the range without increasing the radius, I would look into raycasting from the player outwards and creating collisions that way.
A third way would be to add a sphere collider around your player that extends beyond them and mark it as a trigger. Then use OnTriggerEnter instead of OnCollisionEnter and find the objects that enter the trigger.
I'm unable to increase the radius of of the Character Controller because it will effect the collision of the character in the world. I only want to test for tagged GameObjects.
For your second suggestion, I don't believe that raycasting works with characters controlers.
Raycasting will work. The link you gave states that you should not use OnCollisionEnter. I added to my original post.