Game Development Reference
In-Depth Information
31.
}
32.
33.
//Compute the rotation around x axis based on
34.
//up and down arrow keys
35.
if(Input.GetKey(KeyCode.DownArrow)){
36.
pitch = -pitchSpeed * Time.deltaTime;
37.
} else if(Input.GetKey(KeyCode.UpArrow)){
38.
pitch = pitchSpeed * Time.deltaTime;
39.
} else {
40.
pitch = 0;
41.
}
42.
43.
//Perform rotations around local
44.
// z and local x axes
45.
transform.Rotate(0, 0, roll);
46.
transform.Rotate(pitch, 0, 0);
47.
48.
//Move the plane forward based on flying speed
49.
transform.Translate(0, 0, flySpeed * Time.deltaTime);
50.
51.
//Do not allow the plane to sink below 5 meters
52.
Vector3 pos = transform.position;
53.
if(pos.y < 5){
54.
pos.y = 5;
55.
}
56.
transform.position = pos;
57.
}
58.
}
Listing 14: The plane control system
Search WWH ::




Custom Search