Skip to main content

Motor

A class in Root.Township, the global namespace.

Drives a Turnable mechanism toward a top speed with a set torque. Each frame it solves the whole connected cluster of turnables once and spreads the torque over them.

Constructors​

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

Fields​

4 private and internal fields
MemberWhat it is
private static HashSet<Turnable> calculatingClusterShared set reused to collect the connected turnables each update.
private int lastFrameFrame last handled, so the cluster is only solved once per frame.
private float maximumMotorSpeedTarget speed, scaled by the turnable's moment of inertia.
private float motorTorqueBacking field for Torque (default 10).

Properties​

MemberWhat it is
float Torque { get; set; }The motor's torque. Can be changed at runtime.
Turnable Turnable { get; private set; }The turnable this motor drives.

Methods​

MemberWhat it is
void ModifyTorque(ref float torque)Adds motor torque toward the top speed, limited to motorTorque per second. Marks this frame as handled.
2 private and internal methods
MemberWhat it is
private void Awake()Finds the Turnable on the same object and sets itself as its motor.
private void Update()Once per frame: walks the connected turnables, totals torque and inertia, and applies torque per inertia to each. Jammed clusters get no torque.

Used in​

Members of other types that take, return or hold a Motor: