Search Unity

isKinematic toggle not working

Discussion in 'Scripting' started by unityrookie, Feb 23, 2010.

  1. unityrookie

    unityrookie

    Joined:
    Sep 24, 2009
    Posts:
    34
    I have what is probably any easy problem I can't understand. Basically I have a cube (with a rigidbody attached) suspended in the air that starts out with isKinematic = true. When the user presses the space button, I toggle isKinematic to false, and the cube should then fall to the ground. I can tell the toggle is working by looking at the property in the inspector, but for whatever reason the cube still stays suspended. Here's the code:

    Code (csharp):
    1. var rigidOn:boolean = false;
    2.  
    3.  
    4. function FixedUpdate () {
    5.     if(Input.GetKeyDown("space")) {
    6.         rigidOn = true;
    7.     }
    8.  
    9.     if(rigidOn == true)  {
    10.         rigidbody.isKinematic = false;
    11.     } else {
    12.         rigidbody.isKinematic = true;
    13.     }
    14.    
    15. }
    Why doesn't the cube fall? I know if I add the line rigidbody.useGravity = true below the rigidbody.isKinematic = true line, it does work. However, useGravity is always true from the beginning, I don't understand why I have to explicitly call that.

    Thanks!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Because it's asleep; you have to wake it up.

    --Eric
     
  3. unityrookie

    unityrookie

    Joined:
    Sep 24, 2009
    Posts:
    34
    Thanks Eric. Is setting the useGravity property to true the best way to do that, or is there some other recommended way to wake it up?
     
  4. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    rigidbody.WakeUp()
     
  5. unityrookie

    unityrookie

    Joined:
    Sep 24, 2009
    Posts:
    34
    Perfect. thanks.