Camera problem

Hi all,

My camera is moving through objects and it is looking very bad.

Could some one please help me how to restrict the camera such that it won’t go through objects…

Can you describe your problem more specifically? What is your aim? You can use the camera such as 3rd person shoter ?

Thank you for giving the reply…

I want the camera to be like a third person shooter camera…

how can i make it…

my present camera is moving through objects…

You can use the MouseOrbit.js in Unity3D . As i gathered you want to a script on a camera like WoW(World of Warcraft). And i have the code:

var target : Transform;
var distance = 100.0;

var xSpeed = 250.0;
var ySpeed = 120.0;

var yMinLimit = 200;
var yMaxLimit = 400;

var zoomRate = 20;

private var x = 0.0;
private var y = 0.0;



var prefabs: GameObject; 
var controllingDrag:boolean;

@script AddComponentMenu("Camera-Control/WowCamera")

function Start () {
    var angles = transform.eulerAngles;
  x = angles.y;
  y = angles.x;

	
b=true;
	
	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
		
		
}



function LateUpdate () {

	

	
    if (target&controllingDrag) {
    	if (Input.GetMouseButton(0))
    	{
        x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
        y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
        var test = 0;
        test = y;
    	}
        distance += -(Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime) * zoomRate * Mathf.Abs(distance);
 		if (distance < 2.5)
 		{
 			distance = 2.5;
 		}
 		if (distance > 20)
 		{
 			distance = 20;
 		}
    	
 		
 		y = ClampAngle(y, yMinLimit, yMaxLimit);
 		       
 		//Debug.Log("y: "+y+" test: "+test);
 		
 		if( y == yMinLimit  test == yMinLimit)
 		{
 			// This is to allow the camera to slide across the bottom if the player is too low in the y 
 			distance += -(Input.GetAxis("Mouse Y") * Time.deltaTime) * 10 * Mathf.Abs(distance);
 		}
 		
        var rotation = Quaternion.Euler(y, x, 0);
        var position = rotation * Vector3(0.0, 2.0, -distance) + target.position;
        
        //Debug.Log("Distance: "+distance);
        transform.rotation = rotation;
        transform.position = position;
	}
}

static function ClampAngle (angle : float, min : float, max : float) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);
}

Or you can ask to Google as Wow camera system in Unity3D :slight_smile: