Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
EulerTransform1DofActuator.cs
Go to the documentation of this file.
1 using System;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Actuators {
8  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
9  + "EulerTransformActuator1Dof"
10  + ActuatorComponentMenuPath._Postfix)]
14  [SerializeField]
15  protected Axis _Axis_Of_Motion;
16 
20  [SerializeField] protected string _Layer_Mask = "Obstructions";
21 
25  [SerializeField] protected bool _No_Collisions = true;
26 
30  [SerializeField] protected Space _Relative_To = Space.Self;
31 
35  public override string PrototypingTypeName { get { return "Transform" + this._Axis_Of_Motion; } }
36 
42  protected override void InnerApplyMotion(IMotion motion) {
43  var layer_mask = 1 << LayerMask.NameToLayer(this._Layer_Mask);
44  var vec = Vector3.zero;
45  switch (this._Axis_Of_Motion) {
46  case Axis.X_: // Translational
47  vec = Vector3.right * motion.Strength;
48  break;
49  case Axis.Y_: // Translational
50  vec = -Vector3.up * motion.Strength;
51  break;
52  case Axis.Z_: // Translational
53  vec = -Vector3.forward * motion.Strength;
54  break;
55  case Axis.Rot_x_: // Rotational
56  this.transform.Rotate(Vector3.left, motion.Strength, this._Relative_To);
57  break;
58  case Axis.Rot_y_: // Rotational
59  this.transform.Rotate(Vector3.up, motion.Strength, this._Relative_To);
60  break;
61  case Axis.Rot_z_: // Rotational
62  this.transform.Rotate(Vector3.forward, motion.Strength, this._Relative_To);
63  break;
64  case Axis.Dir_x_: break;
65  case Axis.Dir_y_: break;
66  case Axis.Dir_z_: break;
67  default: throw new ArgumentOutOfRangeException();
68  }
69 
70  if (this._No_Collisions) {
71  if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask)) {
72  this.transform.Translate(vec, this._Relative_To);
73  }
74  } else {
75  this.transform.Translate(vec, this._Relative_To);
76  }
77  }
78  }
79 }