Go kinematic when in collider

I’m really new at scripting so be nice. I’m trying to get a “hand” to grab (go kinematic) when I press the space bar. I only want it to do so if it’s in the collider “ground”. I’m got it to work when not using colliders so something must be wrong with my script. this is the script I’m using. Second one is the one that’s working, but that “grabs” anywhere which I don’t want to do.


function Update() {}

function OnTriggerEnter (other : Collider){

	if (other.gameObject.tag == "ground")
	{
		if (Input.GetKey(KeyCode.Space))
			{rigidbody.isKinematic = true;}
	}
	else
		{rigidbody.isKinematic = false;}

}


function Update() {

    if(Input.GetKey(KeyCode.Space))
	{rigidbody.isKinematic = true;}
else
	{rigidbody.isKinematic = false;}

}

the reason its not working is because you are using OnTriggerEnter, which only occurs in like 1 second or even less, so all the code that is in OnTriggerEnter will be executed in that one second so if u dont press the spacebar on that precise moment its not going to work.

if u want it to work all you have to do is change OnTriggerEnter to OnTriggerStay() and then it should work :slight_smile: