Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Rigidbody3DofActuator.cs
Go to the documentation of this file.
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Actuators {
10  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
11  + "Rigidbody3DofActuator"
12  + ActuatorComponentMenuPath._Postfix)]
13  [RequireComponent(typeof(Rigidbody))]
17  [SerializeField]
18  protected bool _Angular_Actuators;
19 
22  [SerializeField]
23  protected ForceMode _ForceMode = ForceMode.Force;
24 
27  [SerializeField]
28  protected Space _Relative_To = Space.Self;
29 
32  [SerializeField]
33  protected Rigidbody _Rigidbody;
34 
37  string _x;
38 
41  string _y;
42 
45  string _z;
46 
49  public override string PrototypingTypeName { get { return "Rigidbody"; } }
50 
54  protected override void Setup() { this._Rigidbody = this.GetComponent<Rigidbody>(); }
55 
59  protected override void RegisterComponent() {
60  this._x = this.Identifier + "X_";
61  this._y = this.Identifier + "Y_";
62  this._z = this.Identifier + "Z_";
63  if (this._Angular_Actuators) {
64  this._x = this.Identifier + "RotX_";
65  this._y = this.Identifier + "RotY_";
66  this._z = this.Identifier + "RotZ_";
67  }
68 
69  this.Parent =
70  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, this, this._x);
71  this.Parent =
72  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, this, this._y);
73  this.Parent =
74  NeodroidUtilities.RegisterComponent((IHasRegister<IActuator>)this.Parent, this, this._z);
75  }
76 
81  protected override void InnerApplyMotion(IMotion motion) {
82  if (!this._Angular_Actuators) {
83  if (motion.ActuatorName == this._x) {
84  if (this._Relative_To == Space.World) {
85  this._Rigidbody.AddForce(Vector3.left * motion.Strength, this._ForceMode);
86  } else {
87  this._Rigidbody.AddRelativeForce(Vector3.left * motion.Strength, this._ForceMode);
88  }
89  } else if (motion.ActuatorName == this._y) {
90  if (this._Relative_To == Space.World) {
91  this._Rigidbody.AddForce(Vector3.up * motion.Strength, this._ForceMode);
92  } else {
93  this._Rigidbody.AddRelativeForce(Vector3.up * motion.Strength, this._ForceMode);
94  }
95  } else if (motion.ActuatorName == this._z) {
96  if (this._Relative_To == Space.World) {
97  this._Rigidbody.AddForce(Vector3.forward * motion.Strength, this._ForceMode);
98  } else {
99  this._Rigidbody.AddRelativeForce(Vector3.forward * motion.Strength, this._ForceMode);
100  }
101  }
102  } else {
103  if (motion.ActuatorName == this._x) {
104  if (this._Relative_To == Space.World) {
105  this._Rigidbody.AddTorque(Vector3.left * motion.Strength, this._ForceMode);
106  } else {
107  this._Rigidbody.AddRelativeTorque(Vector3.left * motion.Strength, this._ForceMode);
108  }
109  } else if (motion.ActuatorName == this._y) {
110  if (this._Relative_To == Space.World) {
111  this._Rigidbody.AddTorque(Vector3.up * motion.Strength, this._ForceMode);
112  } else {
113  this._Rigidbody.AddRelativeTorque(Vector3.up * motion.Strength, this._ForceMode);
114  }
115  } else if (motion.ActuatorName == this._z) {
116  if (this._Relative_To == Space.World) {
117  this._Rigidbody.AddTorque(Vector3.forward * motion.Strength, this._ForceMode);
118  } else {
119  this._Rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength, this._ForceMode);
120  }
121  }
122  }
123  }
124  }
125 }