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

Confusion with SpringJoint

Discussion in 'Scripting' started by littlelingo, Jul 24, 2006.

  1. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    I am working with the SpringJoint and trying to get a slide down action (like the doors in a cube farm). I sort of have it working, the way I want, with the slide down portion but am having lots of problems to get it to slide back up.

    My current approach is essentially turning the Use Gravity flag for the rigid body on/off from the GUI to try and get the proper effect. What happens is it isn't sliding down quite the way I want but worse after a couple times it starts angling and coming out all whacked.

    I have also started looking into the coding of this a bit and pretty concerned about how to handle that as well but figure that is another topic after it is functioning well. ;-p

    Attached is a screenshot of the mesh and a screenshot of the SpringJoint properties.

    Thanks again in advance for all the help!

    Regards,

    -- Clint
     

    Attached Files:

  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    So you basically don't want it to rotate?

    Just check freeze rotation in the rigidbody.
     
  3. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    DOH! Now I feel more stupid then I already did. ;-)

    One more question, maybe I can redeem myself. <G>

    I was trying to access the rigidbody code wise but wasn't sure on how to do that with the SpringJoint. Here is sort of what I did but it gives an exception which I sort of expected.

    Code (csharp):
    1.  
    2. var updateFlag = false;
    3.  
    4. function FixedUpdate () {
    5.  
    6.     if (updateFlag){
    7.    
    8.         Joint.rigidbody.useGravity = true;
    9.    
    10.     }
    11.  
    12. }
    13.  
    14. function OnMouseDown(){
    15.     updateFlag = true;
    16. }
    17.  
    18. function OnMouseUp(){
    19.     updateFlag = false;
    20. }
    21.  
    Thanks again!
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    just remove the "Joint." infront of rigidbody.useGravity.
     
  5. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Okay, cool.

    So I am not getting the error anymore but my mesh w/ physics is not adhering to the gravity. I can see the values changing and updating but not until I select the Use Gravity in the GUI does it work.

    Any ideas?

    Regards,

    -- Clint
     
  6. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Do I need to addForce in something like an Update to get the object moving?

    TIA,

    -- Clint
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    So you see the useGravity value change in the inspector and if you change the useGravity value from the gui on the very same rigidbody then it works? Are you sure it is the same rigidbody?
     
  8. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Yes,

    I see the value changing in my Script and in the GUI but only when I select it in the GUI does the action occur.

    -- Clint
     
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Apparently there is a problem with rigidbody.useGravity which makes rigidbodies that are sleeping not automatically wake up. You can force them to wake up automatically using this:
    Code (csharp):
    1.  
    2. rigidbody.useGravity = true;
    3. rigidbody.AddForce(0,0,0);
    4.  
    This will be fixed with Unity 1.5.1.
     
  10. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Thanks Joe!

    Regards,

    -- Clint