- Home /
Sphere Collider Trigger not being Triggered on Object with two Colliders
Hi guys,
I have a prefab with a toilet bowl mesh as its only child (don't ask why!), which has the following two colliders:
A mesh collider, used for physics simulation. Its purpose is to keep the player from walking through the toilet bowl. It's not set as a trigger, and it's not convex.
A sphere collider, with isTrigger checked. The idea is to use it to make the lid of the toilet open automatically whenever the player gets close to it.
The toilet bowl has the following script attached to it:
var lid : Transform;
var ring : Transform;
var toiletController : Transform;
function Update ()
{
}
function OnTriggerEnter(other : Collider)
{
if (other.GetComponent (CharacterController))
{
Debug.Log("Player next to toilet, add code to open the lid");
}
}
The lid isn't opening yet because I haven't added the relevant code yet. However, the debug message isn't showing up if the player goes into the sphere collider. This strikes me as being really strange, since the sphere collider has a radius of 3 and is properly-aligned with the toilet bowl. Moreover, the player's character controller only has a height of 0.4 and a radius of 0.18. What am I doing wrong?
MachCUBED
put the trigger code on your player ins$$anonymous$$d of the toilet and see what happens. unless your player isTrigger also?
$$anonymous$$y Player prefab contains a mesh for my player character as its only child, and has Animation, Character Controller, Audio Source, Player $$anonymous$$ovement.js, and PlayerAttack.js components. None of its components has an isTrigger checkbox.
Did you change the code up there from what it was ealier? I don't remember it looking like that.
Edit: ...anyway... try OnCollisionEnter ins$$anonymous$$d of trigger now.
Note: make sure after you get it working, that you also have it to lower the lid after your guy is done. Women won't appreciate it if you leave it up.
I removed OnTriggerEnter() and replaced it with this:
function OnCollisionEnter() {
Debug.Log("Player next to toilet, add code to open the lid");
}
It still didn't work, so I changed it back to OnTriggerEnter(), but without the test to see if it's just the player:
function OnTriggerEnter(other : Collider) {
Debug.Log("Player next to toilet, add code to open the lid");
}
It still doesn't work. I also tried adding debug rays for OnCollisionEnter(), and they didn't show up at all. As for closing the lid, don't worry, the toilet is supposed to be one of those fancy Japanese-style ones, so I won't forget to make it close for the ladies! ;)
I got it to work using OnTriggerEnter(), it turns out that my script was attached to the prefab ins$$anonymous$$d of the mesh. The mesh is the object that has the relevant colliders, not the prefab, so attaching the script to the prefab ins$$anonymous$$d of the enclosed mesh was a stupid mistake on my part.