- Home /
Child sphere collider detection
I've got a gameobject with a rigidbody, and it's child has a sphere collider. Essentially, I want the parent to know when something enters the child's collider. I can't just put the sphere collider on the parent because I have a separate, smaller box collider on it to be able to click it. Does anyone have any ideas? Thanks!
Answer by FlaSh-G · Aug 19, 2020 at 06:54 PM
Rigidbodies "own" all colliders of not just their own GameObject, but its children, too. The only exception is when you have another rigidbody in the hierarchy - the parent rigidbody does not claim any of its colliders.
And all events happening to colliders that belong to a rigidbody get send to all scripts on the GameObject that the rigidbody is on.
@FlaSh-G right now the child is detecting the parent rigidbody. This is the script on the parent: private void OnTriggerEnter(Collider other) { Debug.Log("HitSomething");
if (team != other.tag)
{
AttackScript attack = other.GetComponent<AttackScript>();
if (attack == null)
return;
if (attackTimer <= 0)
{
attackTimer = attackSpeed;
attack.health = attack.health - attackDamage;
}
if (attackTimer > 0)
{
attackTimer -= Time.fixedDeltaTime;
}
}
I can't find the problem in the code. Thanks for helping!
Try just throwing a Debug.Log
into the very start of this method and see if it triggers. If it doesn't, the issue might be with triggering the collision in the first place, not with your hierarchy or script.
I think that he solved the issue already, im not sure
Your answer
Follow this Question
Related Questions
Collider working but not firing OnCollisionXYZ (in parent object) 0 Answers
Dynamically parenting a collider object to a rigidbody object causes collision bug. 1 Answer
Is their a way to find the GameObject a collider is attached to. 3 Answers
How can I access a Collider's GameObject in script? 1 Answer
Getting a collision's bottom-most collider in a hierarchy 2 Answers