Skip to main content

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.

Constructors​

MemberWhat it is
Turnable()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
protected List<Turnable> connectedBacking list for Connected.
protected float radiusBacking value for Radius.
7 private and internal fields
MemberWhat it is
private float frictionTorque lost per second while turning.
private bool isCurrentFlippedWhether this gear turns the opposite way in the current cluster update (every other gear in a chain is flipped).
private bool isDebugInspector flag that nothing reads.
private float massMass used for the moment of inertia (minimum 0.001).
private float speedStarting speed, turned into torque on Awake.
private float torqueCurrent torque; Speed is this over the moment of inertia.
private List<Turnable> turningUnused list in this build.

Properties​

MemberWhat 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​

MemberWhat 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: