P5js // Trying to work out rotation of an object

Hey,

I am trying to make a basic simulation for a drone/quadcopter, with control of each thruster on the drone. The drone itself is a body, with 4 thrusters attached. I am currently working on adjusting the position and rotation of the body based on the position of the thrusters. While I can get the vector from the body center to each thruster, I am having trouble calculating the rotation I should be applying to the body from this. I assume I would use the headings in some way. I have already implemented a way of calculating the position of the body relative to the thrusters, although I haven’t constrained the thrusters to the body yet so they go all over the place.

If you want to check out the code here is a link: P5js Editor

I am still working on this so the code might change here and there, so you might want to make your own copy.

I know the code has a lot of issues as well, and am open to suggestions.

If you are attaching multiple thrusters as fixtures to a body and then applying force to the assemblage, then once you have the outline the implementation strikes me as the perfect thing for a physics engine like cannon.js.

Then you can focus on modeling the copter and interface, not the hairy constraint solver stuff that comes up when four thrusters are all acting at the same time, but in different directions.