-
Notifications
You must be signed in to change notification settings - Fork 0
/
helicoptercontroller.cs
112 lines (103 loc) · 3.52 KB
/
helicoptercontroller.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using UnityEngine;
using System.Collections;
public class HeliMovement : MonoBehaviour {
public Transform HeliFan;
public Transform HeliTailFan;
public float HeliFanSpeed;
public float HeliTailFanSpeed;
public float MaxSpeed;
public float Acceleration;
public float RotX;
public float MovY;
public float MovZ;
public float RotY;
public float TiltY;
public float XRotSpeed;
public float ZRotSpeed;
public float hover;
private float timer;
private float HeliFanAcceleration = 0;
private float HeliTailFanAcceleration = 0;
private float CurFanSpeed = 0;
private float CurTailFanSpeed = 0;
float timer2;
float timer3;
float Zrot;
Quaternion Z;
public Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate () {
Zrot = Mathf.LerpAngle (transform.localEulerAngles.z, 0.0f, ZRotSpeed * Time.deltaTime);
Z = Quaternion.Euler (transform.localEulerAngles.x, transform.localEulerAngles.y, Zrot);
rb.centerOfMass = Vector3.forward * 0.5f + Vector3.down * 2;
if (Input.GetKey (KeyCode.UpArrow) && MovZ > 2000000) {
rb.AddRelativeTorque (Vector3.right * RotX * XRotSpeed);
}
if (Input.GetKey (KeyCode.DownArrow) && MovZ > 2000000) {
rb.AddRelativeTorque (Vector3.left * RotX * XRotSpeed);
}
if (Input.GetKey (KeyCode.LeftArrow) && MovZ > 2000000) {
rb.AddRelativeTorque (0, -RotY, 0);
} else {
rb.MoveRotation (Z);
}
if (Input.GetKey (KeyCode.RightArrow) && MovZ > 2000000) {
rb.AddRelativeTorque (0, RotY, 0);
}else {
rb.MoveRotation (Z);
}
if (Input.GetKey(KeyCode.W)) {
rb.AddRelativeForce (Vector3.up * MovY);
}
if (Input.GetKey(KeyCode.S)) {
rb.AddRelativeForce (Vector3.down * MovY);
}
if (Input.GetKey (KeyCode.Q)) {
rb.angularVelocity = Vector3.up * TiltY;
}
if (Input.GetKey (KeyCode.E)) {
rb.angularVelocity = Vector3.down * TiltY;
}
if (Input.GetKey (KeyCode.A)) {
MovZ += Time.deltaTime * Acceleration;
}
if (Input.GetKey (KeyCode.D)) {
MovZ -= Time.deltaTime * 1000000;
}
if (Vector3.Angle (Vector3.up, transform.up) >= 0 && CurFanSpeed > 25) {
rb.AddRelativeForce (Vector3.forward * MovZ * Time.deltaTime);
}
if (CurFanSpeed > 25) {
rb.velocity = new Vector3 (0, hover, 0);
} else {
rb.velocity = new Vector3 (0, 0, 0);
}
if (MovZ > MaxSpeed) {
MovZ = MaxSpeed;
}
if (MovZ < 0) {
MovZ = 0;
}
}
// Update is called once per frame
void Update () {
HeliFanAcceleration = timer;
HeliTailFanAcceleration = timer2;
timer += Time.deltaTime;
timer2 += Time.deltaTime;
timer3 += Time.deltaTime;
if (timer >= 5) {
timer = 5;
}
if (timer2 >= 5) {
timer2 = 5;
}
CurFanSpeed = HeliFanSpeed * HeliFanAcceleration;
HeliFan.transform.Rotate (0, 0, CurFanSpeed);
CurTailFanSpeed = HeliTailFanSpeed * HeliTailFanAcceleration;
HeliTailFan.transform.Rotate (CurTailFanSpeed, 0, 0);
}
}