Collision script problem

Hey guys,

I have this script below:

var otherObjectTag = “terrain”;

function OnCollisionEnter (hit : Collision){
	if(hit.gameObject.tag == otherObjectTag){
		print ("HITTING INTO THE TERRAIN");
	}
}

I’ve set the terrain with the tag “terrain”, but when I run the game and hit into the terrain, (it’s an aircraft game) nothing gets printed to the console…

If you know what’s going wrong, or if you have a better script, then please post…!!!

Thanks

-Grady

Are you sure the aircraft and the terrain have the right combination of collider properties to generate Collision messages? You can test that with the snippet below. Since you asked about alternatives, I personally favor Layers over Tags for this sort of thing, and besides any move away from string-based comparisons is always beneficial. Lookup “Layer action matrix / Layer based collision” in the Unity3 docs…it will be at the bottom of any of the Collider references pages.

function OnCollisionEnter (hit : Collision){
    if(hit.gameObject.tag == otherObjectTag){
        print ("HITTING INTO THE TERRAIN");
    }
    else
        print("Collision message generated, just not matching terrain tag");
}