I have a rigidbody with a box collider, and have been doing some testing with “Cube” primitives.
The object grows in size, and I resize the collider to match.
collider.center = collider.transform.InverseTransformPoint(renderer.bounds.center);
collider.size = collider.transform.InverseTransformDirection(renderer.bounds.size);
I am wondering if I am missing resizing something though…
In certain spots the box collider actually passes through cubes in the scene - and this is when I am looking at the box collider in scene view and can see it very obviously. Any ideas? Do I have to change something about the rigidbody when I resize the box collider? Are there moments when solid objects do pass through each other? Can objects pass through each other when going at sufficiently high speeds?
This may be complicated by the fact that I am trying to keep everything in a 2d plane. The rigidbody has rotation frozen, and at the end of FixedUpdate I have this line:
rigidbody.MovePosition(rigidbody.position - (rigidbody.position.z - currentZPosition) * Vector3.forward);
(To make sure the z position of the rigidbody never changes)[/code]