1
votes

I have been over this a 100 times in the past. Collisions and triggers in unity. This page: http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html has a collision chart which shows that a Rigidbody Trigger Collider should send a trigger message AT ALL TIMES when it collides with something other then air.

So my detection zone is a Rigidbody trigger box collider, with gravity turned off. Then i have my ''triggers'' which are on the playable character, those are empty game object with just a box collider that has IS TRIGGER on it.

when testing this however, Nothing happens.

I attached the following code on my rigidbody:

public class HitTest : MonoBehaviour {
    void OnTriggerStay(){
        Debug.Log("Hit! Obj: "+this.gameObject.name);
    }
}

The problem is resolved by making the other object a rigidbody as well, but this messes up a lot of stuff on the playable character somehow, i want to prevent this at all costs.

Any ideas on what i did wrong here?

Thanks in advance, Smiley

1
I'm not sure what's up. Have you tried posting on answers.unity3d.com or on their support forums? - Chris Sinclair
I suppose i will try that then. Thanks for the try anyway. - Smileynator

1 Answers

1
votes

This is incorrect:

void OnTriggerStay() { // Look at here
Debug.Log("Hit! Obj: "+this.gameObject.name); // NOTE: This will show the name of your object
}

The correct is:

void OnTriggerStay(Collider others) { // Look at here
Debug.Log("Hit! Obj: "+others.gameObject.name); // NOTE: This will show the name of the object you collided

}

Hope this helps! :)