Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
CompassSensor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
5 using UnityEngine;
6 
7 namespace droid.Runtime.Prototyping.Sensors.Experimental {
11  [AddComponentMenu(SensorComponentMenuPath._ComponentMenuPath
12  + "Compass"
13  + SensorComponentMenuPath._Postfix)]
14  [ExecuteInEditMode]
15  [Serializable]
16  public class CompassSensor : Sensor,
17  IHasDouble {
20  [SerializeField]
21  Vector2 _2_d_position = Vector2.zero;
22 
25  [Header("Observation", order = 103)]
26  [SerializeField]
27  Vector3 _position = Vector3.zero;
28 
31  [SerializeField]
32  Space3 _position_space = new Space3 {
33  DecimalGranularity = 1,
34  _Max_Values = Vector3.one,
35  _Min_Values = -Vector3.one
36  };
37 
40  [Header("Specific", order = 102)]
41  [SerializeField]
42  UnityEngine.Transform _target = null;
43 
47  public override string PrototypingTypeName { get { return "Compass"; } }
48 
51  public Vector3 Position {
52  get { return this._position; }
53  set {
54  this._position = this._position_space.IsNormalised
55  ? this._position_space.ClipNormaliseRound(value)
56  : value;
57  this._2_d_position = new Vector2(this._position.x, this._position.z);
58  }
59  }
60 
64  public Space2 DoubleSpace {
65  get {
66  return new Space2(this._position_space.DecimalGranularity) {
67  _Max_Values =
68  new Vector2(this._position_space
69  ._Max_Values.x,
70  this._position_space
71  ._Max_Values.y),
72  _Min_Values =
73  new Vector2(this._position_space
74  ._Min_Values.x,
75  this._position_space
76  ._Min_Values.y)
77  };
78  }
79  }
80 
84  public Vector2 ObservationValue { get { return this._2_d_position; } set { this._2_d_position = value; } }
85 
89  protected override void PreSetup() { }
90 
91  public override IEnumerable<float> FloatEnumerable {
92  get { return new[] {this.Position.x, this.Position.z}; }
93  }
94 
98  public override void UpdateObservation() {
99  this.Position = this.transform.InverseTransformVector(this.transform.position - this._target.position)
100  .normalized;
101  }
102  }
103 }
Vector3 ClipNormaliseRound(Vector3 v)
Definition: Space3.cs:55