- Home /
Make FirstPersonCam follow car direction
Basically I am making a driving/racing game. I have a cockpit camera: the script below allows you to manually rotate the camera while driving. This is not what I want. Hopefully someone can help me so it rotates horizontily when I press "A" or "D" (Left or Right arrows as well).
Blockquote
#pragma strict
var distance = 5.0;
var xSpeed = 125.0;
var ySpeed = 125.0;
var rightclicked : boolean = false;
private var x = 0.0;
private var y = 0.0;
@script AddComponentMenu("Camera-Control/Mouse Orbit")
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
}
function Update (){
if (Input.GetMouseButtonDown(1)){
rightclicked = true;
}
if (Input.GetMouseButtonUp(1)){
rightclicked = false;
}
}
function LateUpdate () {
if (rightclicked == true) {
x += Input.GetAxis("Mouse X") * xSpeed * distance* 0.04;
y += Input.GetAxis("Mouse Y") * ySpeed * distance* 0.04;
var rotation = Quaternion.Euler(-y, x, 0);
transform.rotation = rotation;
}
}
Blockquote
Comment