Camera Script Errors

I’m following a script from Game Development with Unity Second Edition and I have these errors:

  1. js(37,40): BCE0005: Unknown identifier:‘wantedRotationAngle’.
  2. js(44,17): BCE0005: Unknown identifier:‘DistanceDampingX’.
  3. js(67,65): BCE0020: An instance of type ‘UnityEngine.Transform’ is required to access non static member ‘rotation’.

Current Script:

var target : Transform;
//the distance for X and Z for the camera to stay from the target
var distance = 5.0;
//The distance in Y for the camera to stay form the target
var height = 4.0;

//Speed controls for the camera--how fast it catches up to the moving object
var heightDamping = 2.0;
var rotationDamping = 3.0;
var distancedampingX = 1;
var distanceDampingZ = 1;

//The camera controls for looking at the target
var camSpeed = 2.0;
var smoothed = true;

function LateUpdate()
{
	//Check to make sure a target has been assigned in Inspector
	if(!target)
		return;
	
	//Calculate the current rotation angles, positions,
	//and where you want to camera to end up
	RotationAngle = target.eulerAngles.y;
	wantedHeight = target.position.y + height;
	wantedDistanceZ = target.position.z - distance;
	wantedDistanceX = target.position.x - distance;
	
	currentRotationAngle = transform.position.y;
	currentHeight = transform.position.y;
	currentDistanceZ = transform.position.z;
	currentDistanceX = transform.position.x;
	
	//Damp the rotation around the Y axis
	currentRotationAngle = Mathf.LerpAngle
		(currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
	
	//Damp the distance
	currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
	currentDistanceZ = Mathf.Lerp(currentDistanceZ,
		wantedDistanceZ, distanceDampingZ * Time.deltaTime);
	currentDistanceX = Mathf.Lerp(currentDistanceX, wantedDistanceX,
		DistanceDampingX * Time.deltaTime);	
		
	//Convert the angle into a rotation
	currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
	//set the new position of the camera
	transform.position -= currentRotation * Vector3.forward * distance;
	transform.position.x = currentDistanceX;
	transform.position.z = currentDistanceZ;
	transform.position.y = currentHeight;
	
	//Make sure the camera is always looking at the target
	LookAtMe();
}

function LookAtMe()
{	
	if(smoothed)
	{
		//Find the new rotation value based upon the target an camera's
		//current position.  Then interpolate smoothly between the two
		//using the specified speed setting.
		var camRotation = Quaternion.LookRotation(target.position -
	transform.position);
		transform.rotation = Quaternion.Slerp(Transform.rotation, camRotation,
	Time.deltaTime * camSpeed);
	}
	
	//This defaul will flatly move with the targeted object
	else
	{
		transform.LookAt(target);
	}
}

@script AddComponentMenu("Moalia/SmooothFollowCamera")
  1. You’re trying to use wantedRotationAngle but haven’t defined what it is anywhere
  2. and 3. Capitalisation is important in programming… :slight_smile: Look carefully on the lines mentioned.