Hi everyone
I want to write script that will allow to drive car so I’ve been following tutorial series from FlatTutorials(Youtube) , he scripts in javascript I want that in C#, I almost Copied whole Camera script in C# but camera is not moveing to car, it just rotates looking at the car.
There’s the tutorial
Script 11:51
and my script which has this prob:
using UnityEngine;
using System.Collections;
public class CarCameraScript : MonoBehaviour {
public Transform car;
public float distance = 6.4f;
public float height = 1.4f;
public float rotationDamping = 3.0f;
public float heightDamping = 2.0f;
public float zoomRacio = 0.5f;
private Vector3 rotationVector ;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void LateUpdate () {
var wantedAngle = car.eulerAngles.y;
var wantedHeight = car.position.y + height;
var myAngle = transform.eulerAngles.y;
var myHeight = transform.position.y;
myAngle = Mathf.LerpAngle (myAngle,wantedAngle, rotationDamping * Time.deltaTime);
myHeight = Mathf.Lerp (myHeight,wantedHeight,heightDamping * Time.deltaTime);
var currentRotation = Quaternion.Euler (0,myAngle,0);
transform.position = car.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.position = new Vector3 (0, myHeight,0);
transform.LookAt (car);
}
}
I think there’s some problem with this
var myAngle = transform.eulerAngles.y;
C# wants that like this transform.eulerAngles = new vector3(x,y,z)
But I don’t know how to get y value without typing this way var myAngle = transform.eulerAngles.y;
Damn I wrote Debug.Log(myAngle) and it did work even on this
var myAngle = transform.eulerAngles.y;
So yeah. Help.