Object passing through at high speeds

Hi,

I am trying to make 3d smooth tetris. However, objects are passing through others. I created a small project to simulate this.

Project can be downloaded from: https://dl.dropboxusercontent.com/u/2118263/object-passing-through.zip

Here are the notes:

  • There is a plane, a static cube and a moving cube.
  • Static cube has position = (4.5,0.5,0), rigidbody, box collider, freeze position, freeeze rotation, no gravity and “Finish” tag.
  • Moving cube has position = (0, 0.5, 0), rigidbody, box collider, continous dynamic collision detection and Mover Script(below).

Moving cube was moving towards Static Cube, and onTrigger enter, i set the speed = 0 and log the position. The output is “Entered position @(3.6, 0.5, 0)” however I expect it to be exactly “Entered position @3.5, 0.5, 0)”. Can you explain why it cannot enter the trigger exactly @3.5.

Because of this problem, I also started to think about not using collisions. Any suggestions to make a 3d smooth tetris?

Thanks.

 public class Mover : MonoBehaviour {
    
    	int speed = 5;
    
    	// Use this for initialization
    	void Start () {
    	
    	}
    	
    	// Update is called once per frame
    	void FixedUpdate () {
    		rigidbody.MovePosition (rigidbody.position + Vector3.right * speed * Time.deltaTime);
    	}
    
    	void OnCollisionEnter(Collision other){
    		if (other.gameObject.tag == "Finish") {
    			Debug.Log ("Entered position @" + rigidbody.position);
    			speed = 0;
    		}
    
    	}
    }

Physics in games aren’t contiguous like in real life (as far as we know), but discrete. This means that all physics computation is done in intervals, and these computations include collision detection. In Unity the default interval is 0.02 seconds, i.e. 50 times each second.

Now, let’s imagine we have a euclidean coordinate system (x,y) and there is an object at 0,0 with a speed 1 unit/second along the x-axis. Our computation interval is two seconds, so this means we will only notice the object at points (2,0), (4,0), etc…

In Unity, the interval of physics computation can be changed in Edit → Project Settings → Time. It is called “Fixed Timestep”. Setting that value to 0.1 or smaller will decrease the interval of computation (= CPU usage) but will allow you to notice smaller movements in your objects and possibly allow you to stop your tetris pieces in time.

Instead of using physics, I would build a tetris on a 2D grid. If you look at the tetrises of yesteryear (also lots of the modern ones), you will notice they are very blocky, which means that they too are most likely built on a grid.