I’m new to Unity, but I thought you always needed a ‘Is Trigger’ box checked on a rigid body to use the ‘OnTriggerEnter2D’ functions. But, on my current project, the trigger is activating whenever the player collides with the collider.
There is already an OnCollisionEnter2D function that does one thing, but that same collider also activates the OnTriggerEnter2D, even when the trigger rigid body is placed on a different game object. So, the trigger rigid body activates the event, but so does the other collider.
Is there someway to make the other rigid body (that isn’t trigger) not activate the trigger?
Yes, you are doing it right, there is just a little you need to add for it to only activate with specific characters. As follows:
Step 1. Give your players/characters tags in the inspector menu.
Step 2. Make sure your trigger or collision function returns a collider variable. Example:
void OnTriggerEnter2D(Collider2D other){
}
The variable “other” is being defined above as a Collider2D, aka whatever triggers the collider will be set to the variable.
Step 3. Add the simple code to check to see if whatever collides or triggers to collider is what you want. Example:
void OnTriggerEnter2D(Collider2D other){
if(other.tag == "YourTagNameHere"){
//Run code here
}
}
Simple as that! If this helped, please accept the answer. If not, feel free to ask!