Im using the OnCollisionEnter-function to detect a collision between an enemy and the player, but it will only record a collision when they are both moving towards eachother. When for instance the player jumps on top of the enemy, nothing is triggered, and the same goes for when the player runs in to the enemy from behind.
Code:
function OnCollisionEnter (collision : Collision) {
if ( collision.gameObject.tag == "Player" ) {
Debug.Log("Hit Player");
}
}
Are you using Character Controller? If so, have you tried to use OnControllerColliderHit instead?
Ok, since I needed the Enemy (which lacks a Character Controller since collisions between two character controllers seem to be a bad idea according to most posts Ive read) to be the detecting party, what I needed to do was to add (not replace) another collider to the player. I then tagged it, made it a trigger, and made a OnTriggerEnter-call detect it from the enemy's script.
function OnTriggerEnter (collision : Collider)
{
if ( collision.gameObject.tag == "Player_Collider" )
{
Debug.Log("Hit Player");
}
}
This enabled the enemy to detect hits with the player even when the collision came from behind or from above.
,u can make an empty game object and just put something like a gimzo to let u know where u wanna hit him and place it the place u want but not on the player just infront or beside and use it as trigger so once it enters this area its triggered whatever for a cutscene kill or whatever.
ok i answered it but i didnt notice it was year earlier
I have a very similar issue! When I jump on a collider with my character(has a rigidbody) from top, it triggers the OnCollisionEnter function. However, If I slider onto the collider from a side (so that the character doesn’t fall from top on it), it does nothing.
Is there any way to check when I’m on the collider when I slide onto it from a side?
PS: the collider is a simple platform and the character has a cube collider and rigidbody. I need to apply new velocity OnCollisionEnter regardless of which angle I fall onto the collider from.