OnControllerColliderHit Design Issue

Hi all,

I want to have an object detect when the player bumps into it, and I want the script which detects that on the object rather than the player if possible, as I think it’s a better design.

Is there any vaguely elegant way to achieve this? I can attach a script to the player and then use controllerColliderHit.collider.SendMessageUpwards( “OnHitController”, controllerColliderHit ) or something, but the ControllerColliderHit is from the perspective of the CC and not the object that it has hit…

Is there something I’m overlooking?

Cheers!
J

Really? No one?

Put the function on the object instead of the player.

OnTriggerEnter or OnCollisionEnter depending on your needs.

That won’t work as this is a CharacterController colliding with a Collider.

Then put OnCollisionEnter on the collider. What issues is that creating for you?

When a character controller collides with a collider, OnCollisionEnter/Stay/Exit are not called on the collider, only OnControllerColliderHit is called, and only on the character controller, no events are recieved by the collider.

That’s quite odd. Walking into a box generates no message, but the box landing on my head does cause an OnCollisionEnter event. I’d only been looking for OnCollisionEnter on moving objects, not static ones, so I just assumed it worked both ways.
Ew.

I think the SendMessage option is the way to go. You can always create an array and pass that as the arguments - for exampls,

var arguments : Array = new Array();
arguments.Add( controllerCollision );
arguments.Add( this );
thing.SendMessage( "HitController", arguments );

Hopefully that’s sufficiently modular and helpful.

Indeed that’s the option I found myself faced with. The problem left with that is that the Collision info generated is from the perspective of the character controller, and not from the thing that was hit. I guess I might need to make a custom CollisionInfo class for this… Gah! Yet another example of Unitys weird quirks!

Is this considered a bug? Why is it so easy to create bombs that explode when they hit anything BUT the player? Attaching collision handlers to the player seems like a bad idea from a design perspective. Bombs should be responsible for exploding themselves, not the player.