- Home /
Make isKinematic false when touching a Collider?
I have an issue with my javascript, I want to make non-kinematic an GameObject when another GameObject touch it but nothing happen, no error, etc. This is my Script :
var target : Transform;
var bullet : Transform;
function OnCollisionStay(collisionInfo : Collision) {
if(collisionInfo.gameObject == 'Bullet') {
var rb : Rigidbody;
rb = target.GetComponent(Rigidbody);
rb.isKinematic = false;
}
}
thanks for helping me.
What's the issue? Is there an error message? Does nothing happen?
Could you post a screen shot of inspector information for the gameObject this script is attached to?
I see a couple of problems here, but nothing that should keep the code from working. First OnCollisionStay() gets called each frame during a collision. OnCollisionEnter() would work better. And you don't have to use GetComponent() to get the Rigidbody.
#pragma strict
var target : Transform;
var bullet : Transform;
function OnCollisionEnter(collisionInfo : Collision) {
if(collisionInfo.gameObject == 'Bullet') {
target.gameObject.rigidbody.is$$anonymous$$inematic = false;
}
}
But as far as I can see you code should work. What is happening?
Answer by Owen-Reynolds · Mar 23, 2013 at 01:03 AM
Try this for reference (3rd on a Search "unity oncollisionenter"): http://answers.unity3d.com/questions/18873/oncollisionenter.html
gameObject==Bullet
isn't quite right, and that shows how to fix. You'd have to set your bullets to be tagged (the Unity docs explain this pretty well, and tags are useful.) Or, look for a version that uses ".name". But then carefully check the bullet names -- they may be "Bullet(clone)" if you are spawning them.