Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Obstruction.cs
Go to the documentation of this file.
2 using UnityEngine;
3 
4 namespace droid.Runtime.Utilities.Misc.Extensions {
5  public class Obstruction : MonoBehaviour,
7  Vector3 _last_recorded_move;
8  Quaternion _last_recorded_rotation;
9  Vector3 _previous_position;
10  Quaternion _previous_rotation;
11 
12  public bool IsInMotion() {
13  return this.transform.position != this._previous_position
14  || this.transform.rotation != this._previous_rotation;
15  }
16 
17  public bool IsInMotion(float sensitivity) {
18  var distance_moved = Vector3.Distance(this.transform.position, this._last_recorded_move);
19  var angle_rotated = Quaternion.Angle(this.transform.rotation, this._last_recorded_rotation);
20  if (distance_moved > sensitivity || angle_rotated > sensitivity) {
21  this.UpdateLastRecordedTranform();
22  return true;
23  }
24 
25  return false;
26  }
27 
28  void UpdatePreviousTranform() {
29  this._previous_position = this.transform.position;
30  this._previous_rotation = this.transform.rotation;
31  }
32 
33  void UpdateLastRecordedTranform() {
34  this._last_recorded_move = this.transform.position;
35  this._last_recorded_rotation = this.transform.rotation;
36  }
37 
38  void Start() {
39  this.UpdatePreviousTranform();
40  this.UpdateLastRecordedTranform();
41  }
42 
43  void Update() { this.UpdatePreviousTranform(); }
44  }
45 }