Search Unity

Making a Cell Membrane that Deforms with Physics

Discussion in 'Scripting' started by Vimalakirti, Feb 19, 2010.

  1. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    I am creating the inside of a human cell for a biology game and want it to move naturally, kind of like a jellyfish moves, but I'm short on ideas as to how to make this work.

    I'm thinking that a sphere mesh with rigid bodies attached to the outside would work, but I'm not sure how to go about that. There is a great rope script here: http://forum.unity3d.com/viewtopic.php?t=37137 that maybe could be adapted to create a sphere.

    Perhaps a grid of rigid bodies comprising a sphere would work, but I'm not sure about the parenting issues. They could all be parented to one object and have sphere colliders keeping them spaced apart correctly (like a dandelion's seeds make up a sphere)...

    Ultimately there will have to be a mesh created in Max or Blender that the physics will affect, so maybe I should be starting with the rig for that, then attach rigid bodies to the bones...

    I'm groping here, and open to any and all ideas that you may have. It's a real challenge for me and I'm just hoping that someone may have an idea.

    Thanks for any help.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    the softbody physics script on the unifycommunity might be a good starting point depending on the target hardware
     
  3. Wox

    Wox

    Joined:
    Dec 14, 2009
    Posts:
    93
    Rigged and skinned a sphere to test. Added some colliders, rigidbodies and spring joints to it.

    Didnt get it right when the ball rotated. Must somehow make the outer rigidbodies point to the centre rigidbodie.
    But the "jellyfish moves" seems ok when u just drop it on a plane.

     
  4. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    Those are two great answers!

    I'm having some trouble getting the softbody script to work for me... getting a 'can't find normals' type of error.

    Glad to see the rigid body rig idea is working... that's more familiar ground for me.

    Bottom line on the choice between the two would be how CPU intensive each one is... The softbody script looks like it will use some real juice, but the rig will need a script to make it behave like a gushy jellyfish.
     
  5. Wox

    Wox

    Joined:
    Dec 14, 2009
    Posts:
    93
  6. Vimalakirti

    Vimalakirti

    Joined:
    Oct 12, 2009
    Posts:
    755
    Wox,

    Hey! That's IT!

    Was that a mesh rigged and imported from Maya or Max or Blender?? Maybe you could explain a little of how you put that together and the script? I haven't used Spring Joints yet, I'll have to look that up. Thanks for including the pic of the inspector window.

    Great work!
     
  7. Wox

    Wox

    Joined:
    Dec 14, 2009
    Posts:
    93
    The rigging is made in Maya. The trick to get the rotating to work was to have the same local orientation on the outer bones as the middle/parent (rotated there pivot's).



    To see local orientation axis in Maya: Display -> Transform Display ->local orientation axis.

    Then I just added this code to every outer joint:

    Code (csharp):
    1.  
    2. var target : Transform; //Middle parent joint
    3.  
    4. function Start () {
    5. // to prevent collision with the middle sphere collider
    6.  Physics.IgnoreCollision(target.collider, collider);
    7. }
    8.  
    9. function FixedUpdate(){
    10. // to get the same rotation as the middle(parent) joint.
    11.   transform.localRotation = Quaternion.identity;
    12. }
    13.  
    Every joint has a rigidbody.
    All outer joints have a spring joint connected to the centre joint.

    All joints has a sphere collider, the centre joint has sphere collider with radius 0.8, if u want more jelly just make it smaller.

    The spring values you have in the pic of the inspector window as you have seen.

    Good luck and let us see your result.
     
  8. ArcherAaron4

    ArcherAaron4

    Joined:
    Jan 3, 2013
    Posts:
    1
    $shpere_axis.png Hope this is not a stupid question but i was looking to do something similar with a character in my game, however i'm using blender to rig the sphere and i cant quite seem to get the local rotation of the outermost parts of the armatures to match up. Any ideas?