- Home /
Game object inheriting children colliders
I have a script in my game, where the player checks when it collides with the ground and then sets "isGrounded" true, and sets it false when the player leaves collision with the ground-- the script allows for limiting jumping while in midair.
Anyhow, it works when I have a single GameObject plane that I reference-- but I tried collecting all my surfaces into an empty game object and checking for collision with that. It doesn't seem to work. What I'm trying to do it get a parent game object who's collision shape is the sum of all it's children's shape. Here's my code:
public GameObject floor;
public void jump()
{
if(isGrounded)
rigidbody.AddForce(new Vector3(0,300,0));
}
void OnCollisionEnter(Collision c)
{
if(c.gameObject == floor)
{
isGrounded = true;
}
}
void OnCollisionExit (Collision c)
{
if(c.gameObject == floor)
{
isGrounded = false;
}
}
And then I plug my parent-game object (of all the surface area I want to count as the floor) into the script, and it does not register the collision handlers.
How could I have the parent game object have the same collision box as all it's children? Or is there a better way to do this? Thank you in advance.
Answer by Yusaku · Jan 19, 2014 at 08:24 PM
Are u setting the parent object to a rigidbody? if not try that probably as kinematic my understanding is as long as parent is rigidbody this should work.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using parent tag on whole gameObject 1 Answer
Collision Won't Work 0 Answers
collisions in character not working! 2 Answers
Issue with GameObject has been destroyed but it is not destroyed 1 Answer
Adding ChildObject 2 Answers