How Do I Set A 2D Rigidbidy as isKinematic = true through a script?

#pragma strict

var gameController : GameController;
var rb: Rigidbody2D;

function Start () {
rb = gameObject.GetComponent (Rigidbody2D);
    var gameControllerObject : GameObject = GameObject.FindWithTag ("GameController");
    if (gameControllerObject != null)
    {
        gameController = gameControllerObject.GetComponent (GameController);
    }
    if (gameController == null)
    {
        Debug.Log ("Cannot find 'GameController' script");
    }

};

function Update () {

};


function OnTriggerEnter2D(other: Collider2D)
{
   		if (other.gameObject.CompareTag ("Player"))
   		{
  			SpawnLoop();
  			gameController.AddScore();
  			Debug.Log("A Phone has made contact with the Player");
   			}
   		if (other.gameObject.CompareTag ("Floor"))
   		{
   			SpawnLoop();
  			Debug.Log("A Phone has made contact with the Floor");
   			}
   }
   ;


function SpawnLoop()
{
transform.position = Vector2(transform.position.x, 6);
rb.isKinematic = false;
};

The 2D rigidbody isn’t being set to is kinematic.
What am I doing wrong?

Line 45 you’ve written:

rb.isKinematic = false;

and you’re not sure why isKinematic is not being set to true

Hi

On line 7, you store a reference to "this object’s rigid body’ in a member variable called “rb”:

rb = gameObject.GetComponent (Rigidbody2D);

And on line 45, in SpawnLoop, you then set its ‘isKinematic’ property to ‘false’:

rb.isKinematic = false;

So to set its ‘isKinematic’ property to ‘true’, you would simply change that ‘false’ to ‘true’:

    rb.isKinematic = true;

Hope that clarifies stuff a bit :slight_smile:

-Chris