Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
IndexedMotionActuator.cs
Go to the documentation of this file.
1 using System;
3 using UnityEngine;
4 
5 namespace droid.Runtime.Prototyping.Actuators {
8  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
9  + "IndexedMotion"
10  + ActuatorComponentMenuPath._Postfix)]
14  [SerializeField]
15  protected string _Layer_Mask = "Obstructions";
16 
19  [SerializeField]
20  protected bool _No_Collisions = true;
21 
24  [SerializeField]
25  protected Space _Relative_To = Space.Self;
26 
29  public override string PrototypingTypeName { get { return "IndexedMotion"; } }
30 
36  protected override void InnerApplyMotion(IMotion motion) {
37  var layer_mask = 1 << LayerMask.NameToLayer(this._Layer_Mask);
38 
39  Vector3 vec;
40  switch ((int)motion.Strength) {
41  case 1:
42  vec = Vector3.forward;
43  break;
44  case 2:
45  vec = Vector3.back;
46  break;
47  case 3:
48  vec = Vector3.left;
49  break;
50  case 4:
51  vec = Vector3.right;
52  break;
53  default:
54  throw new ArgumentOutOfRangeException();
55  }
56 
57  if (this._No_Collisions) {
58  if (!Physics.Raycast(this.transform.position, vec, Mathf.Abs(motion.Strength), layer_mask)) {
59  this.transform.Translate(vec, this._Relative_To);
60  }
61  } else {
62  this.transform.Translate(vec, this._Relative_To);
63  }
64  }
65  }
66 }