1 using System.Collections.Generic;
7 namespace droid.Runtime.Prototyping.Sensors.Rays {
11 [AddComponentMenu(SensorComponentMenuPath._ComponentMenuPath
13 + SensorComponentMenuPath._Postfix)]
16 [SerializeField] Vector3 _direction;
19 [Header(
"Specific", order = 102)]
21 GameObject _nearest_object;
23 [Header(
"Observation", order = 103)]
28 [SerializeField] Vector3 _rotation;
30 [SerializeField]
string _tag =
"";
35 public override string PrototypingTypeName {
get {
return "Nearest" + this._tag; } }
40 public Vector3 Position {
41 get {
return this._position; }
49 public Vector3 Rotation {
50 get {
return this._rotation; }
58 public Space3 PositionSpace {
get {
return this._position_space; } }
59 public Space3 DirectionSpace {
get {
return this._direction_space; } }
60 public Space3 RotationSpace {
get {
return this._rotation_space; } }
62 public Vector3 Direction {
63 get {
return this._direction; }
71 public override IEnumerable<float> FloatEnumerable {
88 this._nearest_object = this.FindNearest();
90 if (this.ParentEnvironment != null) {
91 this.Position = this.ParentEnvironment.TransformPoint(this._nearest_object.transform.position);
92 this.Direction = this.ParentEnvironment.TransformDirection(this._nearest_object.transform.forward);
93 this.Rotation = this.ParentEnvironment.TransformDirection(this._nearest_object.transform.up);
95 this.Position = this._nearest_object.transform.position;
96 this.Direction = this._nearest_object.transform.forward;
97 this.Rotation = this._nearest_object.transform.up;
103 GameObject FindNearest() {
104 var candidates = FindObjectsOfType<GameObject>();
105 var nearest_object = this.gameObject;
106 var nearest_distance = -1.0;
107 foreach (var candidate
in candidates) {
108 if (candidate.CompareTag(
this._tag)) {
109 var dist = Vector3.Distance(this.transform.position, candidate.transform.position);
110 if (nearest_distance > dist || nearest_distance < 0) {
111 nearest_distance = dist;
112 nearest_object = candidate;
117 return nearest_object;
override void UpdateObservation()
Vector3 ClipNormaliseRound(Vector3 v)