Collision Detection Doesn't work on more that one object?

Hi,
I am having some real trouble with collision detection.

I have a ship and some 2 different size asteroids. I can get the ship to collide just fine with one of the asteroids. It wont collide with the second size.

I have since tried to add new objects, just a simple cube with box collider, and I cannot even get the ship to hit that either!

So I am close to giving up on Unity, I have spent over 3 weeks now just trying to get an object to hit another.

Simple question: Can one object hit more than 2 others using the function OnTriggerEnter (other : Collider) code?

here is my detection code which is in one of the scripts attached to the ship…

function OnTriggerEnter (other : Collider)
{
if ( other.GetComponent( testcol) )
{
	print("hit cube!");
//This NEVER works!!! a simple cube with a box collider and a script component attached to it called testcol
}

if ( other.GetComponent( ProgressAsteroid)  !ship_dead ) 
{
print("Hit asteroid!");
//This works!! There 
}

}

Perhaps there are some rules regarding other.GetComponent() which I havent worked out yet, I am at a loss to work out what I am doing wrong.

Thanks in advance for any help.[/code]

Collision works fine. I’m not sure what your problem is.

Why not simply print(other.gameObject.name) outside the if-statements so you can see every collision that takes place? Then you’d know whether the problem is that the collision isn’t being detected at all, or that your test (looking for the component) is the problem.

My guess is that (a) the script isn’t called testcol, but TestCol or something… so it’s not being found, or (b) that testcol isn’t attached directly to the same object as the collider but to a child or parent or something.

Thanks for the tips. That debug code is certainly good. I managed to get working, although I am not 100% what I did. I think putting code in the routine on the asteroid helped (it only consisted of an empty updat before). Another thing I added was an ontriggerenter for the asteroid. So

  • the ship routine has an ontriggerenter() which actually does the work
  • the asteroid has an ontriggerenter which is empty

Does this really help though I’d am I being crazy?

Unity is art not science :slight_smile: