x


OnCollisionEnter only working with frontal collisions?

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");
    } 
} 
more ▼

asked Mar 22 '10 at 12:06 PM

Daniel 1 gravatar image

Daniel 1
31 8 8 11

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

Are you using Character Controller? If so, have you tried to use OnControllerColliderHit instead?

more ▼

answered Mar 22 '10 at 02:15 PM

rlbaldi gravatar image

rlbaldi
159 3 5 10

No, I havent tried that but will - thanks. But is that function only triggered from the Players point of view (ie when attached to the Player, which is the object with the Character Controller) or can it be triggered from the enemy, which in this case only has a collider (no character controller)?

Mar 22 '10 at 06:29 PM Daniel 1

On the enemy you should still use OnCollisionEnter/OnTriggerEnter.

Jun 10 '10 at 01:29 PM rlbaldi
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 22 '10 at 11:05 PM

Daniel 1 gravatar image

Daniel 1
31 8 8 11

(comments are locked)
10|3000 characters needed characters left

,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.

more ▼

answered Jul 03 '11 at 01:30 AM

codeguard gravatar image

codeguard
1

(comments are locked)
10|3000 characters needed characters left

ok i answered it but i didnt notice it was year earlier

more ▼

answered Jul 03 '11 at 01:31 AM

codeguard gravatar image

codeguard
1

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Sep 10 '11 at 11:54 AM

lukas77i gravatar image

lukas77i
1 6 6 7

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5051
x2482
x1682

asked: Mar 22 '10 at 12:06 PM

Seen: 2592 times

Last Updated: Sep 10 '11 at 11:54 AM