AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AC_BaseRigidbody_Controller.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using System;
5 using Commons;
6 using Communicator;
7 
8 namespace AirControl
9 {
10  [RequireComponent(typeof(Rigidbody))]
11  [RequireComponent(typeof(AudioSource))]
12  public class AC_BaseRigidbody_Controller : MonoBehaviour
13  {
14  #region Variable
15  protected Rigidbody rb;
16  protected AudioSource aSource;
17  private bool hasEntered;
18 
19 
20  #endregion
21 
22  #region Builtin Methods
23  // Methods to be called before start goes here
24  public virtual void Awake()
25  {
26  // Debug.Log("Airplane Instanciated");
27  // Instantiate(Resources.Load("AirplanePhysics/Art/Objects/Airplanes/IndiePixel_Airplanes/Prefabs/Cessna-152.prefab",typeof(GameObject)));
28 #if UNITY_EDITOR
29  // init DB
30  // not applicable to unity webGL deployment as this is not supported
32 #endif
33 
34 
35  }
36  // Start is called before the first frame update
37  public virtual void Start()
38  {
39  rb = GetComponent<Rigidbody>();
40 
41  aSource = GetComponent<AudioSource>();
42  // Dont allow audio to play on start
43  if(aSource){
44  aSource.playOnAwake = false;
45  }
46 
47  }
48 
49  // Update is called once per frame
50  void FixedUpdate()
51  {
52  if(rb){
53  HandlePhysics();
54  }
55 
56  }
57 
58  void OnCollisionStay(Collision col)
59  {
60  //Allow collision penality once
61  if (StaticOutputSchema.IfCollision == false)
62  {
63  //reward function
64  StaticOutputSchema.Reward -= 100f;
65  // Collision detection
66  DateTime now = DateTime.Now;
67  // Debug.LogFormat(now +" - Collided with : {0} , Counter : {1}, reward : {2}",col.gameObject.tag, StaticOutputSchema.Counter, StaticOutputSchema.Reward);
68  StaticOutputSchema.IfCollision=true;
69  StaticOutputSchema.CollisionObject = col.gameObject.tag;
70  }
71 
72 
73  }
74 
75  // void OnTriggerStay(Collider col)
76  // {
77  // if (StaticOutputSchema.IfCollision == false)
78  // {
79  // if(col.CompareTag("Fence"))
80  // {
81  // //reward function
82  // StaticOutputSchema.Reward -= 100f;
83  // // Collision detection
84  // DateTime now = DateTime.Now;
85  // Debug.LogFormat(now +" - Collided with : {0} , Counter :{1}, reward : {2}",col.gameObject.tag, StaticOutputSchema.Counter, StaticOutputSchema.Reward);
86  // StaticOutputSchema.IfCollision=true;
87  // StaticOutputSchema.CollisionObject = col.gameObject.tag;
88  // }
89  // }
90 
91  // }
92  #endregion
93 
94  protected virtual void HandlePhysics(){
95 
96  }
97 
98 
99 
100  }
101 
102 }
Communicator.IOInit
Input Output init Writting schema files to the disk for reference
Definition: IOInit.cs:17
AirControl.AC_BaseRigidbody_Controller
Definition: AC_BaseRigidbody_Controller.cs:12
Communicator.IOInit.CreateSchema
static void CreateSchema()
Create new schem if the *schema.json if it exists or not. These schema can be used for to format pyth...
Definition: IOInit.cs:47
AirControl
Definition: AirplaneSelector.cs:8
Communicator
Definition: InputHandle.cs:10
Commons
Definition: AirplaneProperties.cs:14