AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
autopilot.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEditor;
4 using UnityEngine;
5 using Commons;
6 
7 namespace AirControl
8 {
9  public class autopilot : MonoBehaviour
10  {
11  #region Variables
12  public Rigidbody airplane;
13  public Transform target;
14  public float speed =10f;
15 
16  #endregion
17 
18  #region InbuildMethod
19  // Start is called before the first frame update
20  void Awake(){
21  airplane = GameObject.Find(CommonFunctions.ActiveAirplane).GetComponent<Rigidbody>();
22  }
23 
24  // Update is called once per frame
25  void Update()
26  {
27  if (airplane.transform.position.y > 100)
28  {
29  Debug.Log("Looking at target");
30 
31  Vector3 relativePos = target.position - airplane.position;
32 
33  // the second argument, upwards, defaults to Vector3.up
34  Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
35  airplane.transform.localRotation = rotation;
36  }
37 
38  }
39  #endregion
40  }
41 }
42 
AirControl.autopilot
Definition: autopilot.cs:9
AirControl
Definition: AirplaneSelector.cs:8
Commons
Definition: AirplaneProperties.cs:14