how to make the camera rotate around the player instead of..

well im using a camera script (dont remember where i found it)

heres the problem:

with this script, the camera rotates around the offset i create… but i want it to rotate around the player

the script:

var target : Transform;
var targetOffset = Vector3.zero;
var distance = 4.0;

var lineOfSightMask : LayerMask = 0;
var closerRadius : float = 0.2;
var closerSnapLag : float = 0.2;

var xSpeed = 200.0;
var ySpeed = 80.0;

var yMinLimit = 0;
var yMaxLimit = 80;

private var currentDistance = 10.0;
private var x = 0.0;
private var y = 0.0;
private var distanceVelocity = 0.0;

function Start () {
    var angles = transform.eulerAngles;
    x = angles.y;
    y = angles.x;
	currentDistance = distance;
	
	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

function LateUpdate () {
    if (target) {
        x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
        y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
 		
 		y = ClampAngle(y, yMinLimit, yMaxLimit);
 		       
        var rotation = Quaternion.Euler(y, x , 0);
        var targetPos = target.position + targetOffset;
        var direction = rotation * -Vector3.forward;
		
        var targetDistance = AdjustLineOfSight(targetPos, direction);
		currentDistance = Mathf.SmoothDamp(currentDistance, targetDistance, distanceVelocity, closerSnapLag * .3);
        
        transform.rotation = rotation;
        transform.position = targetPos + direction * currentDistance ;
		
    }
}

function AdjustLineOfSight (target : Vector3, direction : Vector3) : float
{
	var hit : RaycastHit;
	if (Physics.Raycast (target, direction, hit, distance, lineOfSightMask.value))
		return hit.distance - closerRadius;
	else
		return distance;
}

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);
}

ive tried so many things and none of those worked

can someone help me with this?

thanks

The script looks okay to me.

The first line of the script is var target:Transform. The script attached to your camera should then have a field you can set to the gameobject you want as your target. Is that set? The script is set up to use that target’s transform but it can’t if that value is null.

Drag and drop your character from the Hierarchy window into the “Target” field in the Inspector window to set it to your character.

the “problem” is that the camera rotates around the offset that i created… i want it to rotate around the player

everything else is good

EDIT:

i want the camera to be facing the offset and to rotate around the player

You can use transform.LookAt on the camera’s transform to make it point at a target object.