- Home /
OnCollisionEnter isnt called when player lands on object
I have an OnCollisionEnter event checking to see if the player collides with a pickup. This works if I hit the object from the side but if I jump on it the collision event will not fire in any way. I checked and the player is still trying to accelerate downward while on top of the object but he just sits there. Anyone know why this might be happening?
Please check is there any other object on the top of pickup.
Answer by nt314p · Jul 31, 2017 at 11:15 PM
Although I am not sure why that is happening, I suggest you use the OnTriggerEnter function. Simply check the Is Trigger check mark in the pickup's collider and whenever anything collides with the pickup, the OnTriggerEnter function will run.
Another advantage to the Is Trigger being checked is that the player won't be slowed down by the pickup.
Example code (C# sorry if you're using java):
void OnTriggerEnter (Collider other) {
if (other.gameObject.CompareTag("Player")){
//Run command
Destroy(this.gameObject);
}
}
Hope this helps!