Scripting Question in a CameraScript from racing tutorial

Hi,

I’m currently doing the car tutorial and I have a question for you.

inside the camera’s script:
function LateUpdate () {

  • // Early out if we don’t have a target*

  • if (!target)*

  • return;*

  • // Get the forward direction of the target*
    _ forward = target.TransformDirection (Vector3.forward);_

  • // Get the target position*
    _ targetPosition = target.position;_

  • // Place the camera distance meters behind the target*
    _ transform.position = targetPosition - forward * distance;_

  • // And move the camera a bit up*

  • transform.position.y += height;*

  • // Always look at the target*

  • transform.LookAt (target);*
    }

the forward and targetPosition are something like variables? because it seems to be used like they are.

also, the wantedRotationAngle, wantedHeight, currentRotationAngle, currentHeight etc. in the smooth camera script:

function LateUpdate () {

  • // Early out if we don’t have a target*

  • if (!target)*

  • return;*

  • // 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);_

I understand what is happening in the script but I’m just a little confused about what those terms actually are.

You are correct, they are all variables. Since the examples are in JavaScript you don’t have to explicitly declare the type of variable like you have to in C#. In instances where the compiler can “guess” the type, the variables will be statically typed, otherwise there type will be determined at run time. For example

targetPosition = target.position;

targetPosition will be typed as a Vector3 by the compiler (I think :)) since target.posiition returns a Vector3. It could have been typed explicitly like

var targetPosition : Vector3 = target.position;

Here, you are telling the compiler that this variable will be a Vector3. Those that like to do the extra typing tend to go on and on about clarity, runtime errors, blah, blah, blah, or something like that :stuck_out_tongue:

Oh, thanx a lot!!!