Question about OnTriggerEnter

Alright, I have been working on this for three hours with no progress.

I have weapon models floating around my scene, and when I touch one, I want it to become my players active weapon.

I am using the First Person Controller Prefab as my player, and have added a capsule collider to the prefab and set the collider to Is Trigger. I also added this script:

function OnTriggerEnter(other : Collider)
{
	if(other.CompareTag("FlameThrower"))
	{
		Debug.Log("Getting Flamethrower");
		BroadcastMessage("SelectWeapon",0);
	}
	if(other.CompareTag("MachineGun"))
	{
		Debug.Log("Getting Machine Gun");
		BroadcastMessage("SelectWeapon",1);
	}
}

Each weapon model floating around my scene has the appropriate tag (MachineGun or FlameThrower). However, even when I run into a model, nothing is ever printed out.

All of the models have a mesh collider and are set to Is Trigger.

Anyone have any idea why these triggers aren’t being set off?

You shouldn’t do that…the character controller is already a capsule collider. Also the models shouldn’t be using mesh colliders; not that it would prevent it from working, but it’s a lot of extra computation compared to primitive colliders for no benefit.

–Eric

Ok, I removed the capsule collider from the first person controller and changed the mesh colliders to box colliders.

Still nothing :?

How I would try to find the bug:

First: Comment the "If"s out. See, if you get any reedback from the function.

And if so, Second:
Try something like “if(other.tag==“FlameThrower”)”.

Also: Check if you havent mistaken “Layer” as Tag… Someday I was confused and made a layer instead of a tag :slight_smile:

Alright, with a little tinkering I got it to work. Well, sort of. It didn’t work on the first person controller, so I am just making a script to go on the weapons themselves, and got something working now.

Thanks