Hi,
I am attempting to make a system where an AI unit can move itself with an arbitrary set of thrusters. All movement in the engine my engine is controlled by the physics engine -- to move or rotate an object, a force vector must be applied on the object.
Objects have a list of Thrusters (a thruster is not necessarily a piece of hardware like on a ship -- it's just a designator for where a force can be applied relative to an object).
At the end of each frame, the net force on an object is summed up to find the net force and acceleration.
A thruster has:
x, y, z offset (in local object coordinates)
x, y, z direction (in local object coordinates)
current magnitude (in absolute force units)
maximum magnitude (in absolute force units)
Most of the code interacts with the thrusters by setting their percentage activated.
Currently I have an AI ship that can follow the player and hover, as well as keep itself level when balls are thrown at it, by firing off the correct thrusters to keep its angular and linear velocity a set amount, and its pitch a set amount.
However, I have hard-coded the thrusters to be used at this point. But I would like to be able to have an arbitrary set of thruster objects pointing in arbitrary directions with arbitrary maximum magnitudes and the AI calculate which thrusters to fire and at what percentage to get closest to its target position, angle, linear velocity, and angular velocity, at the end of each frame.
I'm not great at math and not sure where to start with solving for the thruster percentages. What is most confusing to me is, for example, the fact that the ship can fire off a back-right thruster, which will turn it left and also propel it forward.