Game Development Reference
In-Depth Information
14.
15.
//Mouse look speed on both axis
16.
public float horizontalMouseSpeed = 0.9f;
17.
public float verticalMouseSpeed = 0.5f;
18.
19.
//Max allowed cam vertical angle
20.
public float maxVerticalAngle = 60;
21.
22.
//Storing player velocity for movement
23.
private Vector3 speed;
24.
25.
//Mouse position in previous frame,
26.
//important to measure mouse displacement
27.
private Vector3 lastMousePosition; 28.
29.
//Store camera transform
30.
private Transform camera;
31.
32.
void Start () {
33.
lastMousePosition = Input.mousePosition;
34.
//Find camera object in children
35.
camera = transform.FindChild("Main Camera");
36.
}
37.
38.
void Update () {
39.
//Step 1: rotate cylinder around global Y
40.
//axis based on horizontal mouse displacement
41.
Vector3 mouseDelta = Input.mousePosition - lastMousePosition;
42.
43.
transform.RotateAround(
44.
Vector3.up, //Rotation axis
45.
mouseDelta.x *
46.
horizontalMouseSpeed *
47.
Time.deltaTime);//Angle 48.
49.
//Get current vertical camera rotation
Search WWH ::




Custom Search