Camera Effect + Translating US to C#

Hello everyone, i have a camera script that makes the cam follow player and this was working great until we wanted to add an effect that would have the cam move further from the player and zoom in based on the player’s speed, my artist tells me that they use this in movies and it should look great.

Now i figured out how to do this(untested and not sure if there’s a better way) but the problem is that i can’t access the speed because this script is in unityscript and the other one in c#, placing the c# script in standard assets isn’t an option because other scripts depend on it aswell and changing the script execution time doesn’t take away the thrown error so i can’t press play and test.

I tried translating it to c# but that causes issues because this line does not work in c#:
transform.position.y = currentHeight;
Throws error: Cannot modify the return value of Transform.Position because it’s not a variable

And i don’t know how to cache some of the variables, you’ll see which ones i’m talking about
Full (US) script:

/*This camera smoothes out rotation around the y-axis and height.
Horizontal Distance to the target is always fixed.

For every of those smoothed values we calculate the wanted value and the current value.
Then we smooth it using the Lerp function.
Then we apply the smoothed values to the transform's position.*/

    var target : Transform;
    var playerC : PlayerControl;
    var cam : Camera;
    // The distance in the x-z plane to the target
    var distance = 10.0;
    // the height we want the camera to be above the target
    var height = 5.0;
    // Damping
    var heightDamping = 2.0;
    var rotationDamping = 3.0;
    
    //Cache for performance
    var wantedRotationAngle;
    var wantedHeight;
    var currentRotationAngle;
    var currentHeight;
    var currentRotation;
    
    function Awake(){
        playerC = GameObject.FindWithTag ("Player").GetComponent(PlayerControl);
        cam = GetComponent(Camera);
    }
    function LateUpdate () {
        
    	// 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
    	currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
    	
        // Set the position of the camera on the x-z plane to:
        //Change distance and fov based on player speed
    	if(playerC.currThrust > 1050) distance += currThrust/200; cam.fieldOfView += currThrust/200; 
    	// 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);
    }

Translated so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControl : MonoBehaviour {

    Transform target;
    PlayerControl playerC;
    Camera cam;
    // The distance in the x-z plane to the target
    float distance = 10;
    // the height we want the camera to be above the target
    float height = 5;
    // Damping
    float heightDamping = 2;
    float rotationDamping = 3;

    //Cache for performance ****Not sure how to translate these****
    /*var wantedRotationAngle;
    var wantedHeight;
    var currentRotationAngle;
    var currentHeight;
    var currentRotation;*/


    void Awake()
    {
        playerC = GameObject.FindWithTag("Player").GetComponent<PlayerControl>();
        cam = GetComponent<Camera>();
    }
    void LateUpdate()
    {

        var wantedRotationAngle = target.eulerAngles.y;
        var wantedHeight = target.position.y + height;

        var currentRotationAngle = transform.eulerAngles.y;
        var currentHeight = transform.position.y;

        currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

        currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);

        var currentRotation = Quaternion.Euler(0, currentRotationAngle, 0);

        if (playerC.currThrust > 1050) distance += playerC.currThrust / 200; cam.fieldOfView += playerC.currThrust / 200;
        
        transform.position = target.position;
        transform.position -= currentRotation * Vector3.forward * distance;

        // Set the height of the camera  *****Here is the issue*****
        transform.position.y = currentHeight;

        transform.LookAt(target);
    }
}

Thanks in advance

I tried translating it to c# but that causes issues because this line does not work in c#: transform.position.y = currentHeight; Throws error: Cannot modify the return value of Transform.Position because it’s not a variable

The transform.position is a (Vector3) property that can be set or get. You just have to create a new Vector3 with the new position coords.

transform.position = new Vector3( new_x_value, new_y_value, new_z_value );

Heres a simple fix

         // Set the height of the camera  *****Here is the issue*****
         transform.position = new Vector3( transform.position.x, currentHeight, transform.position.z );

You can’t adjust transform.position.y directly, but you can do something like:

Vector3 tempPosition = transform.position;
tempPosition.y = currentHeight;
transform.position = tempPosition;

Those variables you want to cache - you can just do what you did with all the other variables - it looks like they are all floats, so:

float wantedRotationAngle;
float wantedHeight;
//etc...

Creating a vector each time you want to move your camera may not be the optimal thing to do (variable creation + GB…)

Don’t forget that you have the Transform.Translate method to modify position vectors which should be better !