Unity3d and physics.

I’ve been working with a project using unity3 and i cant seem to wrap my head around whats going wrong. Ive triewd a couple different options. One using the dynamic collision detection which doesnt appear to do what i need and a sample script i forget where it came from to attempt to use some scripted physics.

The project itself is a cube and a ball inside. The object is to change the direction of the cube, which in turn changes the balls trajectory and hit blocks that reside in the cube for points. Currently what happens is when you spin the cube too fast or at the right time the ball shoots out of the cube off into the nothingness of space. Ive tried setting various combinations of continuous and dynamic detection on the ball and the cube walls but it doesnt seem to do alot and the script doesnt seem to do what i need as im sure it had another intended purpose. Any insight on what i may be able to do to solve this would be appreciated. Thanks in advance for reading.

#pragma strict

var layerMask : LayerMask; //make sure we aren't in this layer
var skinWidth : float = 0.1; //probably doesn't need to be changed
private var minimumExtent : float;
private var partialExtent : float;
private var sqrMinimumExtent : float;
private var previousPosition : Vector3;
private var myRigidbody : Rigidbody;
//initialize values
function Awake() {
   myRigidbody = rigidbody;
   previousPosition = myRigidbody.position;
   minimumExtent = Mathf.Min(Mathf.Min(collider.bounds.extents.x, collider.bounds.extents.y), collider.bounds.extents.z);
   partialExtent = minimumExtent*(1.0 - skinWidth);
   sqrMinimumExtent = minimumExtent*minimumExtent;
}

function FixedUpdate() {
   //have we moved more than our minimum extent?
   var movementThisStep : Vector3 = myRigidbody.position - previousPosition;
   var movementSqrMagnitude : float = movementThisStep.sqrMagnitude;
   if (movementSqrMagnitude > sqrMinimumExtent) {
      var movementMagnitude : float = Mathf.Sqrt(movementSqrMagnitude);
      var hitInfo : RaycastHit;
      //check for obstructions we might have missed
      if (Physics.Raycast(previousPosition, movementThisStep, hitInfo, movementMagnitude, layerMask.value))
         myRigidbody.position = hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent;
   }
   previousPosition = myRigidbody.position;
}

myRigidbody.position = … is very often not a good idea. Maybe

myRigidbody.MovePosition (hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent);

gives you better results.

Unfortunately I still get the same effect with the variation. it almost seems that the cube is moving too fast in some instances to register the hit although i have slown the cubes ability to spin 100 times or so.