Builtin Library
README.md
ecs.ShaftNetwork
Spec for the ShaftNetwork component, which maps to the native ShaftNetwork: a network of rotating parts and the links between them (a drivetrain, a gear train, a winch drum on a motor, a conveyor drive), solved inside the physics step. The ShaftNetwork component (components/ShaftNetwork) is the authoring surface; it builds these records from a table keyed by name.
Fields
parts: a list of part records:name,inertia,wheel(a WheelCollider entity id),joint(a hinge Joint's entity id),torque,throttle,curve(flat pairs of speed in rad/s and torque in N·m),friction,brake,damping; written back every tick:speed,drive_torque,brake_torque,link_torque, andproblem(why the part turns on its own though it names a wheel or a joint, empty when it turns with it).links: a list of link records:name,kind("Shaft","Gear","Clutch","Differential","Spring"),a,b,input,ratio,capacity,engage,locked,preload,bias,stiffness,damping; written back every tick:torque,lock_torque,slip,slipping,windup.settled, written back every tick: whether the tick held every link, friction, brake and drive where its bounds allow (every shaft and gear at its ratio, every differential at the mean of its sides, every clutch and lock holding inside its capacity or slipping at it). It readsfalsewhen the links ask for speeds the parts cannot take together, and the parts then turn as near to every link as they can come.
ecs.insert(id, ecs.ShaftNetwork {
parts = { { name = "motor", inertia = 0.1, torque = 20 }, { name = "drum", joint = drumId } },
links = { { name = "reduction", kind = "Gear", a = "motor", b = "drum", ratio = 30 } },
})
print(ecs.get(id, ecs.ShaftNetwork):read().parts[2].speed)