Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
TorqueActuator.cs
Go to the documentation of this file.
2 using UnityEngine;
3 
4 namespace droid.Runtime.Prototyping.Actuators.WheelColliderActuator {
8  [AddComponentMenu(ActuatorComponentMenuPath._ComponentMenuPath
9  + "WheelCollider/Torque"
10  + ActuatorComponentMenuPath._Postfix)]
11  [RequireComponent(typeof(WheelCollider))]
12  public class TorqueActuator : Actuator {
13  [SerializeField] WheelCollider _wheel_collider;
14 
18  public override string PrototypingTypeName { get { return "Torque"; } }
19 
23  protected override void Setup() { this._wheel_collider = this.GetComponent<WheelCollider>(); }
24 
28  protected override void InnerApplyMotion(IMotion motion) {
29  this._wheel_collider.motorTorque = motion.Strength;
30  }
31 
32  void FixedUpdate() { ApplyLocalPositionToVisuals(this._wheel_collider); }
33 
36  static void ApplyLocalPositionToVisuals(WheelCollider col) {
37  if (col.transform.childCount == 0) {
38  return;
39  }
40 
41  var visual_wheel = col.transform.GetChild(0);
42 
43  col.GetWorldPose(out var position, out var rotation);
44 
45  var transform1 = visual_wheel.transform;
46  transform1.position = position;
47  transform1.rotation = rotation;
48  }
49  }
50 }