I have an issue with my script, I want to make rb.isKinematic go from true to false when collision is detected. With this script, nothing happens when a supposed collision is happening which means that rb.Kinematic = false does not work... The problem is that collision CANNOT be detected in the first place because rb.isKinematic is initially true (in my other script)! I checked this using Debug.Log to detect collisions. How can I fix this problem?
string lastTagCollided = "";
public Rigidbody rb;
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Pentagon" && lastTagCollided == "Pyramid")
{
rb = GetComponent<Rigidbody>();
rb.isKinematic = false;
transform.DetachChildren();
Destroy (GameObject.FindWithTag("Sphere"));
}
if(col.gameObject.tag == "Pyramid" && lastTagCollided == "Pentagon")
{
rb = GetComponent<Rigidbody>();
rb.isKinematic = false;
transform.DetachChildren();
Destroy (GameObject.FindWithTag("Sphere"));
}
lastTagCollided = col.gameObject.tag;
}
My other script if you are curious:
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Pyramid" || col.gameObject.tag == "Pentagon")
{
rb = GetComponent<Rigidbody>();
rb.isKinematic = true;
gameObject.transform.SetParent (col.gameObject.transform);
}
}