Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
RocketActuator.cs
Go to the documentation of this file.
1 using System;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Actuators.Particles {
10  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
11  + "Particles/Rocket"
12  + ActuatorComponentMenuPath._Postfix)]
13  [RequireComponent(typeof(ParticleSystem))]
14  [RequireComponent(typeof(Rigidbody))]
18  [SerializeField]
19  bool _fired_this_step;
20 
23  [SerializeField]
24  protected ParticleSystem _Particle_System;
25 
29  public override string PrototypingTypeName { get { return "Rocket" + this._Axis_Of_Motion; } }
30 
34  protected override void Setup() {
35  this._Rigidbody = this.GetComponent<Rigidbody>();
36  this._Particle_System = this.GetComponent<ParticleSystem>();
37  var valid_input = this.MotionSpace;
38  valid_input._Min_Value = 0;
39  this.MotionSpace = valid_input;
40  }
41 
44  void LateUpdate() {
45  if (this._fired_this_step) {
46  if (!this._Particle_System.isPlaying) {
47  this._Particle_System.Play(true);
48  }
49  } else {
50  this._Particle_System.Stop(true);
51  }
52 
53  this._fired_this_step = false;
54  }
55 
60  protected override void InnerApplyMotion(IMotion motion) {
61  if (motion.Strength < this.MotionSpace._Min_Value || motion.Strength > this.MotionSpace._Max_Value) {
62  Debug.Log($"It does not accept input {motion.Strength}, outside allowed range {this.MotionSpace._Min_Value} to {this.MotionSpace._Max_Value}");
63  return; // Do nothing
64  }
65 
66  switch (this._Axis_Of_Motion) {
67  case Axis.X_:
68  if (this._Relative_To == Space.World) {
69  this._Rigidbody.AddForce(Vector3.left * motion.Strength);
70  } else {
71  this._Rigidbody.AddRelativeForce(Vector3.left * motion.Strength);
72  }
73 
74  break;
75  case Axis.Y_:
76  if (this._Relative_To == Space.World) {
77  this._Rigidbody.AddForce(Vector3.up * motion.Strength);
78  } else {
79  this._Rigidbody.AddRelativeForce(Vector3.up * motion.Strength);
80  }
81 
82  break;
83  case Axis.Z_:
84  if (this._Relative_To == Space.World) {
85  this._Rigidbody.AddForce(Vector3.forward * motion.Strength);
86  } else {
87  this._Rigidbody.AddRelativeForce(Vector3.forward * motion.Strength);
88  }
89 
90  break;
91  case Axis.Rot_x_:
92  if (this._Relative_To == Space.World) {
93  this._Rigidbody.AddTorque(Vector3.left * motion.Strength);
94  } else {
95  this._Rigidbody.AddRelativeTorque(Vector3.left * motion.Strength);
96  }
97 
98  break;
99  case Axis.Rot_y_:
100  if (this._Relative_To == Space.World) {
101  this._Rigidbody.AddTorque(Vector3.up * motion.Strength);
102  } else {
103  this._Rigidbody.AddRelativeTorque(Vector3.up * motion.Strength);
104  }
105 
106  break;
107  case Axis.Rot_z_:
108  if (this._Relative_To == Space.World) {
109  this._Rigidbody.AddTorque(Vector3.forward * motion.Strength);
110  } else {
111  this._Rigidbody.AddRelativeTorque(Vector3.forward * motion.Strength);
112  }
113 
114  break;
115  case Axis.Dir_x_: break;
116  case Axis.Dir_y_: break;
117  case Axis.Dir_z_: break;
118  default: throw new ArgumentOutOfRangeException();
119  }
120 
121  this._fired_this_step = true;
122  }
123  }
124 }