- Home /
OnColliderStay does not work
Hello guys, I am having a problem with colliders, I am trying to do a conveyor belt, I have the player with a characterController and one box ( the future conveyor belt ) with one box collider. I put this function in the box:
var speed : float = 3.0;
function OnCollisionStay(collisionInfo : Collision)
{
Debug.Log("a");
/*var platformerController : PlatformerController = collisionInfo.gameObject.GetComponent( "PlatformerController" );
if( platformerController )
{
platformerController.setExternSpeed( Vector3( speed, 0, 0 ) );
}*/
}
But it did not work when the character is over the box. Even the Log did not appeared. Can someone give me some light? I tried to put kinemact rigid body in both objects but it didn't work too. Thank you.
Well, I tried to search more in google and I do not find nothing that could help me. I created other cube with the function "OnCollisionEnter", but it did not work too. Only the "OnControllerColliderHit" inside the player works. Any idea guys?
Answer by aldonaletto · Jan 03, 2012 at 03:47 PM
Yes, collisions between CharacterControllers and rigidbodies are weird: OnControllerColliderHit always works fine, but OnCollision events not. When the rigidbody hits the character, OnCollisionEnter events are sent to both; when the character hits the rigidbody, however, this event is almost never sent.
If possible, use OnControllerColliderHit - the alternative would be to have a trigger volume a little larger than the actual collider and use OnTrigger events instead.
That idea worked well, and also solved the problem of the "direction" of the collision. Thank you again aldo =)