- Home /
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;}
}
Answer by IronFurball · Jan 23, 2012 at 08:37 AM
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 :)
1 second? more like exactly one fixed frame (Time $$anonymous$$anager/Fixed Timestep).
Your answer
Follow this Question
Related Questions
Colliders in if statement 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
How to check for collision between a moving kinematic object and an empty object? 3 Answers
Need some help an object collider that stops a timer then displays it on another scene 1 Answer
help! isKinematic from false to true on cloned platforms 2 Answers