x


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.

more ▼

asked Jan 18 '11 at 08:06 PM

Katori gravatar image

Katori
15 4 4 8

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

1 answer: sort voted first

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) ?

more ▼

answered Jan 18 '11 at 08:54 PM

Bob5602 gravatar image

Bob5602
608 15 17 29

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

Jan 18 '11 at 09:02 PM Jessy

Ah good to know

Jan 18 '11 at 09:51 PM Bob5602
(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:

x2493
x1870
x1693
x81

asked: Jan 18 '11 at 08:06 PM

Seen: 508 times

Last Updated: Jan 18 '11 at 08:06 PM