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