Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
VelocityEvaluation.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace droid.Runtime.Prototyping.Evaluation {
10  [SerializeField]
11  Rigidbody _rigidbody = null;
12 
15  public override void InternalReset() { }
16 
21  public override float InternalEvaluate() {
22  var vel_mag = this._rigidbody.velocity.magnitude;
23 
24  this.IsOutsideBound();
25 
26  return vel_mag;
27  }
28 
31  void IsOutsideBound() {
32  if (this.ParentEnvironment.PlayableArea && this._rigidbody) {
33  var env_bounds = this.ParentEnvironment.PlayableArea.Bounds;
34  var rb_bounds = this._rigidbody.GetComponent<Collider>().bounds;
35  var intersects = env_bounds.Intersects(rb_bounds);
36 
37  #if NEODROID_DEBUG
38  if (this.Debugging) {
39  Debug.Log($"{this.ParentEnvironment.Identifier} - {env_bounds}");
40  Debug.Log($"{this._rigidbody.name} - {rb_bounds}");
41  Debug.Log($"Is intersecting - {intersects}");
42  }
43  #endif
44 
45  if (!intersects) {
46  this.ParentEnvironment.Terminate("Actor is outside playable area");
47  }
48  }
49  }
50  }
51 }