Objects passing through collision because of transform.translate


I have an object that falls using rigidbody.AddForce not the default gravity.

And when you press left/right you move the object in order to navigate around obstacles.

My problem is that the player object will often pass through the wall objects i have even used waitForSecconds to temporary disable the controls but the problem still persists.

static var power : float = 0.0;
static var myY : float;

public var upperClampLimit : float; // can be changed form editor
public var lowerClampLimit : float; // can be changed from editor
public var fallAcceleration : float; // can be changed from editor
public var wallSlow : float; //can be changed from editor
public var movementShrinkerhoriz : float; // can be changed form editor
public var movementShrinkervert : float; // can be changed form editor

var shouldMove : boolean = true;
function Start(){
rigidbody.freezeRotation = true;
function Update (){
Debug.Log (shouldMove);  
var horiz : float = Input.GetAxis("Horizontal");
var horizMovement = horiz/movementShrinkerhoriz;

if (shouldMove) {
if (horizMovement!=0){
rigidbody.velocity.x = 0;

var vert : float = Input.GetAxis("Vertical");
var vertMovement = vert/movementShrinkervert;
power = power - vertMovement;   
power = power +fallAcceleration;

if (power <=0){  
power = power +fallAcceleration;
var dist = (transform.position - Camera.main.transform.position).z;
var upBorder = Camera.main.ViewportToWorldPoint(Vector3(0,upperClampLimit,dist)).y;
var downBorder = Camera.main.ViewportToWorldPoint(Vector3(0,lowerClampLimit,dist)).y;   
transform.position.y = Mathf.Clamp(transform.position.y,upBorder,downBorder);

function FixedUpdate (){
myY = (rigidbody.position.y);
rigidbody.transform.position.z = 0;
function OnCollisionEnter(theCollision : Collision){  
if(theCollision.gameObject.name == "wall"){
shouldMove = false;
yield WaitForSeconds(0.5);
shouldMove = true;

if (power <=0){

power = power -wallSlow;

Use the 101-010 button to format code.

.Translate and .position are literally teleportation. If you need physics interactions, you have to use CharacterController.Move or .SimpleMove, or use Rigidbody.AddForce

/end copypasta

So to get your thingy to not go through walls, AddForce for the sideways movement as well.