Coming to an interesting coding problem which is how to do linear programming in Godot.
I've called lp_solve in Unity without too much issue. For Gdscript, it seems I'd need to write a custom binding with GDExtension, which dampens my mood slightly. I could open source it and make the one person making a Marxist city builder very happy.
lp_solve also has a command line app, which isn't the dumbest idea considering the very loose timing requirements I have. We'll see.
oh wow. i’m really interested now! how do you use linear programming for controlling spaceships (at least ig that’s what the screenshot implies?)?
i can see how it would be useful in the marxist city builder for optimization 😅
With some dot and cross products you can get a system of three linear equations that shows how the total front and side forces and torque are affected by the throttle of each engine, e.g.
f_x = X1 t1 + X2 t2 + ... Xn tn
f_y = Y1 t1 + Y2 t2 + ... Yn tn
t = T1 t1 + T2 t2 + ... Tn tn
Every time the ship layout changes (e.g. something blows up), you make 6 linear programs in total, optimizing for one axis and direction and constraining the other two axes to 0. You also constrain the throttles in (-1.0, 1.0) or (0.0, 1.0) depending on the type (I let reaction wheels and "cheat thrusters" go negative).
You end up with 6 objectives that tell you how hard you can go in any direction without adding unwanted side-slip or torque, and 6 responses for each thruster that tells it how hard to work when going in each direction.
Finally, the player or AI controls the ship by giving it a Vector3 control corresponding to the 3 axes. If you scale this so that the manhattan distance is no more than 1, you can just multiply it by the responses you found earlier to get a valid set of throttles even if the player wants to e.g. move diagonally while turning.
I have to go to bed now, but leave it as an exercise for the reader how to control TVC (thrust vector control) thrusters this way.
hint: head-to-tail
