x


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;
        }   
    }
more ▼

asked Apr 29 '10 at 10:27 PM

TinyUtopia gravatar image

TinyUtopia
270 22 26 38

In other words, I would like it to behave like:

Physics.Raycast(transform.position, direction, hit, RaycastLength)

Apr 29 '10 at 10:32 PM TinyUtopia
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 29 '10 at 10:33 PM

Peter G gravatar image

Peter G
15.1k 16 44 137

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.

http://answers.unity3d.com/questions/7573/confused-about-character-controller-ridigbodies-and-collisions

Apr 29 '10 at 10:41 PM TinyUtopia

Raycasting will work. The link you gave states that you should not use OnCollisionEnter. I added to my original post.

Apr 29 '10 at 11:50 PM Peter G
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1765
x549
x111

asked: Apr 29 '10 at 10:27 PM

Seen: 1279 times

Last Updated: Apr 29 '10 at 10:27 PM