Search Unity

Child Object not getting the Collided.

Discussion in 'Scripting' started by pavees, May 8, 2010.

  1. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    hi all,
    I have a player and on a button click i add up a Trolley(Cart) in front of the parent as its child. Now my problem is i am not able to get the collision between the Cart and the Walls, where both are Colliders, but while in the gameplay they dont collide. Why is it not colliding to each other??? :( :( :( :( :( :( :( :( :( :( :( :( :(
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The rigidbody recognises colliders that were parented to the main object at startup. To add new child objects with colliders, use Destroy to remove the old rigidbody and gameObject.AddComponent to add a new one. As the new rigidbody is added, it will register the existence of the child collider:-
    Code (csharp):
    1. Destroy(rigidbody);
    2. gameObject.AddComponent(Rigidbody);
    3. // Also set rigidbody properties here if necessary...
     
  3. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    thanks andeee, I will try it out and let u know the results. Thanks anyways. :D :D :D :D