Before positining the camera do a raycast call, and if it hits something position the camera a little before this point. A schematic view of this code:
var distance : float; //distance of camera from the player
var hit : raycasthit = Physics.Raycast (transform.position, -transform.forward, hit,distance);
if (hit)
//this gets executed if the raycast hits something
Reposition camera using hit.point as a position.
else
Reposition camera using var distance as position.
Reorient camera (using lookAt or something like that)
↧