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
| Member | What it is |
|---|
Motor() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
4 private and internal fields
| Member | What it is |
|---|
private static HashSet<Turnable> calculatingCluster | Shared set reused to collect the connected turnables each update. |
private int lastFrame | Frame last handled, so the cluster is only solved once per frame. |
private float maximumMotorSpeed | Target speed, scaled by the turnable's moment of inertia. |
private float motorTorque | Backing field for Torque (default 10). |
Properties
| Member | What 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
| Member | What 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
| Member | What 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: