Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
EulerTransform3DofActuator.cs
Go to the documentation of this file.
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Actuators {
10  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
11  + "EulerTransform3DofActuator"
12  + ActuatorComponentMenuPath._Postfix)]
16  [SerializeField]
17  protected string _Layer_Mask = "Obstructions";
18 
21  [SerializeField]
22  protected bool _No_Collisions = true;
23 
26  [SerializeField]
27  protected Space _Relative_To = Space.Self;
28 
31  [SerializeField]
32  protected bool _Rotational_Actuators;
33 
36  [SerializeField]
37  protected bool _Use_Mask = true;
38 
42  string _x;
43 
47  string _y;
48 
52  string _z;
53 
56  public override string PrototypingTypeName { get { return "Transform"; } }
57 
60  protected override void Setup() {
61  if (!this._Rotational_Actuators) {
62  this._x = this.Identifier + "X_";
63  this._y = this.Identifier + "Y_";
64  this._z = this.Identifier + "Z_";
65  } else {
66  this._x = this.Identifier + "RotX_";
67  this._y = this.Identifier + "RotY_";
68  this._z = this.Identifier + "RotZ_";
69  }
70  }
71 
74  protected override void RegisterComponent() {
75  this.Parent =
76  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, this, this._x);
77  this.Parent =
78  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, this, this._y);
79  this.Parent =
80  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, this, this._z);
81  }
82 
86  protected override void InnerApplyMotion(IMotion motion) {
87  var layer_mask = 1 << LayerMask.NameToLayer(this._Layer_Mask);
88  if (!this._Rotational_Actuators) {
89  if (motion.ActuatorName == this._x) {
90  var vec = Vector3.right * motion.Strength;
91  if (this._No_Collisions) {
92  if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask)) {
93  this.transform.Translate(vec, this._Relative_To);
94  }
95  } else {
96  this.transform.Translate(vec, this._Relative_To);
97  }
98  } else if (motion.ActuatorName == this._y) {
99  var vec = -Vector3.up * motion.Strength;
100  if (this._No_Collisions) {
101  if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask)) {
102  this.transform.Translate(vec, this._Relative_To);
103  }
104  } else {
105  this.transform.Translate(vec, this._Relative_To);
106  }
107  } else if (motion.ActuatorName == this._z) {
108  var vec = -Vector3.forward * motion.Strength;
109  if (this._No_Collisions) {
110  if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask)) {
111  this.transform.Translate(vec, this._Relative_To);
112  }
113  } else {
114  this.transform.Translate(vec, this._Relative_To);
115  }
116  }
117  } else {
118  if (motion.ActuatorName == this._x) {
119  this.transform.Rotate(Vector3.left, motion.Strength, this._Relative_To);
120  } else if (motion.ActuatorName == this._y) {
121  this.transform.Rotate(Vector3.up, motion.Strength, this._Relative_To);
122  } else if (motion.ActuatorName == this._z) {
123  this.transform.Rotate(Vector3.forward, motion.Strength, this._Relative_To);
124  }
125  }
126  }
127  }
128 }