Hi there.
I have a flight game going and I have the flying part done I just want to land the aircraft. Thing is I have no idea how to do this.
If anyone could give me some sort of idea on how I could that.
Thanks in advance.
Here is the aircraft code, it contains no physics:
public class FlightControls : MonoBehaviour {
public float speed;
private float GUIspeed;
public Text speedCounter;
[Range(0, 50)]public float camForward;
[Range(0, 50)]public float camUp;
// Update is called once per frame
void Update () {
//Camera follow code
Vector3 moveCamTo = transform.position - transform.forward * camForward + Vector3.up * camUp;
float bias = 0.96f;
Camera.main.transform.position = Camera.main.transform.position * bias + moveCamTo * (1.0f-bias);
Camera.main.transform.LookAt(transform.position + transform.forward * 30.0f);
// Makes plane go forward
transform.position += transform.forward * Time.deltaTime * speed;
// Decrease speed when pitched upwards
speed -= transform.forward.y * Time.deltaTime * 2f;
// Sets the speed for the GUI
GUIspeed = speed * 8;
speedCounter.text = "Speed: " + GUIspeed.ToString();
if(Input.GetKey(KeyCode.KeypadPlus)){
speed += 1;
}else if(Input.GetKey(KeyCode.KeypadMinus)){
speed -= 1;
}
if(speed > 173.72f){
speed = 173.72f;
}
// Stalling code will go here
if(speed < 0f){
speed = 0f;
}
// Pitch and Roll control
transform.Rotate(Input.GetAxis("Vertical") * 1.5f, 0.0f, -Input.GetAxis("Horizontal") * 2f);
// Terrain collision detection
float terrainHeightWhereWeAre = Terrain.activeTerrain.SampleHeight(transform.position);
if(terrainHeightWhereWeAre > transform.position.y){
transform.position = new Vector3(transform.position.x,
terrainHeightWhereWeAre,
transform.position.z);
//Can put crash code here
Debug.Log("Crashed");
}
}
}