problem with OnCollisionEnter

Hi guys, I'm trying to make a platform move when the player stands on it, the platform have a rigidbody attached (that I've set kinematic) and the player have a collider and a character controller. I call the function OnCollisionEnter from the platform, but seems that it doesn't work, what could it be? and what's the best way to implement this? thanks

edit: i've noticed that it works fine when I make the platform collide with another rigidbody, but shouldn't it works fine with the character controller?

function OnCollisionEnter(coll : Collision) {
    if(coll.gameObject.tag == "Player" && ontrigger){
        Debug.Log("urtato");
    }
}

@script RequireComponent(Rigidbody) //richiede rigidbody

I think the problem is that this object is kinematic and the player isn't a rigidbody, but a character controller, so any ideas about how should I make this thing?

2 Answers

2

Is your platform's collider by any chance set to Trigger? If so, OnCollisionEnter won't be called, instead OnTriggerEnter will be called.

I don't have much experience with Character Controllers though. I don't think they act upon other objects, so no message is sent to objects they touch. You will be better off using a rigidbody instead in that case.

but I need it to be kinematic, or the platform will fall down, I need it to stay there and move only if it collide with the player, what should I do? If i use a trigger then the player will fall trough it

and I've just tried to make it not kinematic, but the collision doesn't work neither

no the collider isn't set to trigger

Could you put some of your script into your post?

done, there isn't much

Instead of coll : Collision, it should be coll : Collider? I had this error once but it was with an OnTriggerEnter, its worth a shot.

aw no, it gave me a strange error D: Don't really know what to do