I’m adaptating the SuperMarioController and Camera but I had an weird problem.
when I use the code:
print("OnFollowCamera111");
// Early out if we don't have a target
if (!target){
return;
}
print("OnFollowCamera");
// Calculate the current rotation angles
wantedRotationAngle = target.eulerAngles.y;
wantedHeight = target.position.y + height;
currentRotationAngle = transform.eulerAngles.y;
currentHeight = transform.position.y;
// Damp the rotation around the y-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
// Damp the height
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
// The quaternion interface uses radians not degrees so we need to convert from degrees to radians
currentRotation = Quaternion.EulerAngles (0, currentRotationAngle * Mathf.Deg2Rad, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position.y = currentHeight;
// Always look at the target
transform.LookAt (target);
at the update(), everything is just fine and the camera follows whatever it has to follow.
But when the exactly same code is inside a function, the target gets null or kind of… The thing is that the camera simply don’t move.
By the way, the decaration of the target is:
// The target we are following
var target : Transform;
Any clue about what is going on?
TXS!