Camera Zoom-in when collides with rigidbody problem

Hey guys, I’m trying to get my camera to zoom in on the target (my player) when the player collides with a box collider for a dramatic effect. The problem is, nothing happens! I can’t seem to figure out, but it is getting late, maybe someone can help :slight_smile:

Here’s my code (JS)

Attach this to a camera, create a capsule or other as a player+rigidbody, and use a cube collision box with a rigid body and with “Is Trigger” checkmarked.

var target : Transform; //Target to follow
var cameraDistance : float; //Distance from target in the z-axis
var cameraDistance2 : float;
var damping : float; //Damping on the movement of the camera
var maxCameraSpeed : float; //Max speed of camera
var limitCameraSpeed : boolean;

private var velocity : Vector3; //Camera velocity used by the SmoothDamp function
private var t : Transform; //Reference to the transform component of the game object

function Awake() {
	t = transform; //Cache transform component
}

function LateUpdate() {
	if(target) { //If there is a target
		var maxSpeed = (limitCameraSpeed) ? maxCameraSpeed : Mathf.Infinity; //Set max speed depending on limitCameraSpeed boolean
		t.position.x = Mathf.SmoothDamp(t.position.x, target.position.x, velocity.x, damping, maxSpeed); //Damp x-movement (horizontal follow)
		t.position.y = Mathf.SmoothDamp(t.position.y, target.position.y + cameraDistance2, velocity.y, damping, maxSpeed); //Damp y-movement (vertical follow)
		t.position.z = Mathf.SmoothDamp(t.position.z, target.position.z - cameraDistance, velocity.z, damping, maxSpeed); //Damp z-movement (camera distance)
	}

}
function OnTriggerEnter (other : Collider) {
	cameraDistance = 3;

}

I created another file called Trigger_Enter and attached it to my box. However I’m getting an overloaded error message with this code followed by my error. I think I’m getting close!

var cameraDistance : float; //This will become a link to your player health.

function Start () {
     cameraDistance = FindObjectOfType(cameraDistance); //This caches a link to that script.
}

function OnTriggerEnter(other : Collider) {
	cameraDistance = 3;
}

Assets/Scripts/Trigger_Zoom.js(4,39): BCE0017: The best overload for the method ‘UnityEngine.Object.FindObjectOfType(System.Type)’ is not compatible with the argument list ‘(float)’.

bump.

Still haven’t figured it out quite yet