Turnable
A class in Root.Township, the global namespace.
A gear or wheel in a simple torque network: connected turnables share torque, alternate direction, and jam if the loop doesn't fit. Driven by a Motor; Belt is a subclass.
- Listed in Global namespace: T to X
- Inherits or implements
MonoBehaviour,ICircle - Derived types
Belt,Gear
Constructors
| Member | What it is |
|---|---|
Turnable() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected List<Turnable> connected | Backing list for Connected. |
protected float radius | Backing value for Radius. |
7 private and internal fields
| Member | What it is |
|---|---|
private float friction | Torque lost per second while turning. |
private bool isCurrentFlipped | Whether this gear turns the opposite way in the current cluster update (every other gear in a chain is flipped). |
private bool isDebug | Inspector flag that nothing reads. |
private float mass | Mass used for the moment of inertia (minimum 0.001). |
private float speed | Starting speed, turned into torque on Awake. |
private float torque | Current torque; Speed is this over the moment of inertia. |
private List<Turnable> turning | Unused list in this build. |
Properties
| Member | What it is |
|---|---|
List<Turnable> Connected { get; } | Turnables meshed with this one. |
Vector3 Face { get; } | Local forward direction. |
float MomentOfInertia { get; } | Mass times radius squared over 2. |
Motor Motor { get; set; } | Motor driving this turnable, if any. |
Vector3 Position { get; } | Local position. |
float Radius { get; } | Radius of the turnable. |
float Speed { get; } | Torque divided by moment of inertia. |
float Torque { get; set; } | Current torque. Settable. |
Methods
| Member | What it is |
|---|---|
virtual void BranchUpdate(Turnable from, ref float totalTorque, ref float totalMoi, HashSet<Turnable> cluster, ref bool isJammed, bool isFlipped = false) | Adds this turnable's torque and inertia to the cluster totals and walks on; marks the cluster jammed if reached again in the other direction. |
virtual void UpdateWithSystemTorque(float torquePerMoi) | Sets this turnable's torque from the cluster's shared value and turns it. |
protected virtual void ApplyFrictionAndMotor() | Reduces torque by friction, then lets the motor change it. With no friction (or no torque) the torque is reset to 0 first. |
protected virtual void Awake() | Sets the starting torque from the inspector speed. |
protected virtual void BranchToConnected(ref float totalTorque, ref float totalMoi, HashSet<Turnable> cluster, ref bool isJammed, bool isFlipped) | Passes the update on to every connected turnable with the direction flipped. |
protected virtual void OnDrawGizmosSelected() | Draws the radius and lines to connected turnables. |
protected virtual void OnValidate() | Keeps mass above 0 and resets torque from speed. |
protected virtual void Rotate() | Turns the transform around local forward by speed times delta time. |
Used in
Members of other types that take, return or hold a Turnable: