- Home /
Collision triggers do not work on child gameobject
I have an issue with an OnTriggerStay method in a child gameobject. Here is the system I have implemented:
Player (parent): 1. Ground item grabber collider (child) -> kinematic rigidbody, OnTriggerStay detection 2. Weapon Collider (child) -> kinematic rigidbody, OnTriggerStay detection
I am also using layers to separate my colliders. I ensured the "item on the ground" is on the same layer as the "item grabber" and the layer is enabled in my physics options.
I have also tried this system without kinematic rigid bodies, disabling one of the children, placing a rigid body on the parent ONLY and I also tried OnTriggerEnter.
The Ground Item grabber child fails to work none the less and the weapon collider works without fail. Why is that so? Here is the code on the item grabber collider:
public class player_grab_collider : MonoBehaviour
{
MukizuServer _Mukizuserver;
// Use this for initialization
void Start ()
{
_Mukizuserver = GameObject.Find(".MukizuServer").GetComponent<MukizuServer>();
rigidbody.isKinematic = true;
}
void OnTriggerStay (Collider other)
{
Debug.Log("...");
if (player_controller.canClaim && other.gameObject.tag == "Ground Item")
{
_Mukizuserver.SendItemClaimReq(other.gameObject.name);
}
}
}
The Debug.Log is not even called meaning absolutely nothing was detected. Even using other trigger detection methods like OnTriggerEnter it does not work. And yes, the trigger on the "ground item" is enabled. I tried adding rigid body to that as well.
The trigger should be activated by the player by entering somewhere? Do you use the built-in Player Controller?
@$$anonymous$$idgardDev no I don't. And the ground item is an object that spawns when say a monster dies. When the player passes over the item, their grabber object is supposed to set the trigger off and allow the player to pick up the item.
@jaja1 I would recommend you to put a rigidbody on your player, then handle the trigger from him, ins$$anonymous$$d of what you're doing.
So, just put a rigidbody on your player, then leave the trigger as a box collider with the trigger option ticked and without anything else, that would call the OnTriggerStay function definitely.
@$$anonymous$$idgardDev I tried your set up, still does not work. If you want to see my current set up look under the second answer, I made screenshots.
Answer by tanoshimi · Dec 11, 2014 at 06:57 AM
What sort of colliders do your "Ground item grabber collider (child)" and "ground item" have? Note that two mesh colliders cannot collide with each other unless they are convex (documented here).
The collider on the ground item is a simple box collider. The collider on the grabber object is a capsule collider. I checked and I am sure the two intersect at some point.
Answer by FairGamesProductions · Dec 11, 2014 at 11:01 AM
Your ground item should NOT have the trigger enabled, it should be a simple collider with a RigidBody component. A trigger will NOT trigger another trigger...
And your grabber object, should be a trigger WITHOUT a RigidBody component, since there is no actual need to it.
I tried your method but unfortunately no luck. I've been through numerous combinations of rigidbodies and triggers but nothing seems to work yet. This used to work when the collider was attached to parent object. I made it a child because I wanted separate scripts running for the grabber collider and the player's weapon collider.
Can you make a print screen of your setup? I want to see the colliders in the editor.
@FairGamesProductions Here is my full set up. The parent "playerPrefab" has no rigid body attached to it.
Answer by jaja1 · Dec 12, 2014 at 11:23 PM
Not sure why, but I used a box collider instead fort he grabber object and it seems to have worked. If anyone else has some input on this let me know.