Camera "Collision"

I originally posted this in Support, but it might make more sense to put it here :slight_smile:

Here is my script:

function Update () {
    var fwd = transform.TransformDirection (Vector3.forward);
    var lft = transform.TransformDirection (Vector3.left);
    
    var distancePerSecond = Time.deltaTime * 10;
    
    if (Physics.Raycast (transform.position, lft, 1)) {
        transform.Translate (distancePerSecond,0,0);
    }
    
    if (Physics.Raycast (transform.position, -lft, 1)) {
    	transform.Translate (-distancePerSecond,0,0);
    }
    
    if (Physics.Raycast (transform.position, fwd, 2)) {
    	transform.Translate (0,0,-distancePerSecond);
    }
    
}

any better ways to do this?

I have a third person camera and I am trying to end the problem where the camera goes right through objects that are in its way. The above script works okay, except when a big object is in it’s way, it goes through it anyway.

I think you’ll find what you are looking for HERE.