Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Instantiating rigidbodies

Discussion in 'Editor & General Support' started by Richard_B, Jul 27, 2005.

  1. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    I am trying to spawn a Prefab made of a set of rigidbodies. It is just one cube slightly above another. Both cubes are parented to an empty gameobject, "groupObject". There is also a ground plane collider. When starting, normally the top cube falls gently on the the bottom cube and both come gently to rest on the ground plane. If I try to Instantiate the whole group, via something like

    Code (csharp):
    1.  
    2. Instantiate(groupObject,spawnloc.transform.position, spawnloc.transform.rotation);
    3.  
    both cubes appear to be created at the same location and then immedaitely one of the cubes is flung upwards.

    Is this a bug or is there something special that needs to be done to clone a group of rigid bodies?


    many thanks,
    Richard.


    PS If I switch on "isKinematic" for each cube, then they are cloned in the correct location with no flinging, but I don't see were to switch on/off isKinematic with a script.
     
  2. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    I found the problem. I had placed a sphere (which had a collider component) at the spawn location (so I could see the location) and Instantiating a rigid body over collider is not such a good idea - doh!

    Richard.