Question by
kasquer · Sep 13, 2016 at 11:51 AM ·
camerarotationjavascriptjavachild object
How to rotate camera view?
I made a camera as a child of a spaceship trying to make it rotate along with the ship, but it seems to only follow the position of the ship without view rotation. How can I make the camera view rotate too? Script on the spaceship:
#pragma strict
public var Speed : float;
public var MaxSpeed : int;
public var Acceleration : int;
public var Drag : int;
public var Breaks : int;
function Start () {
}
function Update () {
transform.Translate(Vector3.up * (Time.deltaTime*Speed));
if (Input.GetKey ("space")) {
Speed += Acceleration*Time.deltaTime;
} else if (Speed >= 0) {
Speed -= Drag*Time.deltaTime;
}
if (Input.GetKey (KeyCode.LeftControl)) {
Speed -= Breaks*Time.deltaTime;
}
if (Input.GetKey (KeyCode.D)) {
transform.Rotate(0, -1, 0);
}
if (Input.GetKey (KeyCode.A)) {
transform.Rotate(0, 1, 0);
}
if (Speed >= MaxSpeed) {
Speed = MaxSpeed;
}
if (Speed <= 0) {
Speed = 0;
}
}
Comment