- Home /
Big issue with colliders
I've been wrestling with the collision system for a week now and I really, really need help.
I have two objects, both with box colliders and rigidbodies. In my game, they collide quite frequently--in the setup I have now, one runs right into the other and pushes it along the ground. However, this code is in one of the objects:
function OnCollisionEnter(whatHitMe : Collision){
print(whatHitMe.collider.name);
}
But it simply doesn't work. It will never print the name of the collider. I have a similar object that uses a trigger because it doesn't need the physics engine and it works just fine, but this never, ever works.
Can someone please help me understand why this isn't working? I've tried changing to sphere colliders with no luck. It still works as it does now, but the code never, ever triggers.
Answer by Bob5602 · Jan 18, 2011 at 08:54 PM
Does it throw an error? Did you try putting in a Debug.Log("Hit!") or something to see if the code is actually being run? If anything, perhaps it should be print(whatHitMe.gameObject.name) ?
whatHit$$anonymous$$e.gameObject.name won't change anything; .name is a property that returns the same for any component on a game object, or the game object itself.