Question by
Sankacoffee · Dec 04, 2016 at 12:12 AM ·
collisionphysicsrigidbodykinematic
Rigidbody is colliding terrain on isKinematic = false. call although meshes don't touch
Hello everyone,
So, I take a unity treeinstance, I delete it, clone an inactive prefab below terrain, move it to tree position and deactivate isKinematic to make it fall/break, this is my code, called from FixedUpdate:
//tree
GameObject treeBrokenInstance= GameObject.Instantiate(treeBroken);
treeBrokenInstance.transform.parent = null;
Vector3 newPosition = new Vector3();
Terrain ter = Terrain.activeTerrain;
Vector3 terPosition = ter.transform.position;
Vector3 treePosition = tree.position;
newPosition = (Vector3.Scale(ter.terrainData.size, treePosition) + terPosition);
newPosition.y += 10f;
treeBrokenInstance.transform.position = newPosition;
treeBrokenInstance.transform.localScale = new Vector3(1, 1, 1);
treeBrokenInstance.SetActive(true);
treeBrokenInstance.GetComponent<Rigidbody>().velocity = Vector3.zero;
treeBrokenInstance.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
treeBrokenInstance.GetComponent<Rigidbody>().isKinematic = false;
treeBrokenInstance.GetComponent<Rigidbody>().detectCollisions = true;
As soon as I call
treeBrokenInstance.GetComponent<Rigidbody>().isKinematic = false;
treeBrokenInstance.GetComponent<Rigidbody>().detectCollisions = true;
my cloned prefab recieves terrain collision events and fly's away, although I put it a lot above terrain.
I thought that maybe the object receives the collision events since it goes from inactive under terrain to active over terrain in one frametime. So i tried delaying call to these two lines by 5 seconds, so that frame physics is long resolved, but collision with terrain still triggers.
I must be misunderstanding something but I can't figure out what.
Comment