Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Rigidbody1DofActuator.cs
Go to the documentation of this file.
1 using System;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Actuators {
10  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
11  + "Rigidbody1DofActuator"
12  + ActuatorComponentMenuPath._Postfix)]
13  [RequireComponent(typeof(Rigidbody))]
17  [Header("General", order = 101)]
18  [SerializeField]
19  protected Axis _Axis_Of_Motion;
20 
23  [SerializeField]
24  protected ForceMode _ForceMode = ForceMode.Force;
25 
28  [SerializeField]
29  protected Space _Relative_To = Space.Self;
30 
33  [SerializeField]
34  protected Rigidbody _Rigidbody;
35 
38  public override string PrototypingTypeName { get { return "Rigidbody" + this._Axis_Of_Motion; } }
39 
42  protected override void Setup() { this._Rigidbody = this.GetComponent<Rigidbody>(); }
43 
48  protected override void InnerApplyMotion(IMotion motion) {
49  switch (this._Axis_Of_Motion) {
50  case Axis.X_:
51  if (this._Relative_To == Space.World) {
52  this._Rigidbody.AddForce(Vector3.left * motion.Strength, this._ForceMode);
53  } else {
54  this._Rigidbody.AddRelativeForce(Vector3.left * motion.Strength, this._ForceMode);
55  }
56 
57  break;
58  case Axis.Y_:
59  if (this._Relative_To == Space.World) {
60  this._Rigidbody.AddForce(Vector3.up * motion.Strength, this._ForceMode);
61  } else {
62  this._Rigidbody.AddRelativeForce(Vector3.up * motion.Strength, this._ForceMode);
63  }
64 
65  break;
66  case Axis.Z_:
67  if (this._Relative_To == Space.World) {
68  this._Rigidbody.AddForce(Vector3.forward * motion.Strength, this._ForceMode);
69  } else {
70  this._Rigidbody.AddRelativeForce(Vector3.forward * motion.Strength, this._ForceMode);
71  }
72 
73  break;
74  case Axis.Rot_x_:
75  if (this._Relative_To == Space.World) {
76  this._Rigidbody.AddTorque(Vector3.left * motion.Strength, this._ForceMode);
77  } else {
78  this._Rigidbody.AddRelativeTorque(Vector3.left * motion.Strength, this._ForceMode);
79  }
80 
81  break;
82  case Axis.Rot_y_:
83  if (this._Relative_To == Space.World) {
84  this._Rigidbody.AddTorque(Vector3.up * motion.Strength, this._ForceMode);
85  } else {
86  this._Rigidbody.AddRelativeTorque(Vector3.up * motion.Strength, this._ForceMode);
87  }
88 
89  break;
90  case Axis.Rot_z_:
91  if (this._Relative_To == Space.World) {
92  this._Rigidbody.AddTorque(Vector3.forward * motion.Strength, this._ForceMode);
93  } else {
94  this._Rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength, this._ForceMode);
95  }
96 
97  break;
98  case Axis.Dir_x_: break;
99  case Axis.Dir_y_: break;
100  case Axis.Dir_z_: break;
101  default:
102  throw new ArgumentOutOfRangeException();
103  }
104  }
105  }
106 }