8
\$\begingroup\$

I am developing a physics based game with spaceships.

A spaceship is constructed from circles connected by joints. Some of the circles have engines attached.

Engines can rotate around the center of circle and create thrust. I want to be able to move the ship in a direction or rotate around a point by setting the rotation and thrust for each of the ship's engines.

How can I find the rotation and thrust needed for each engine to achieve this?

enter image description here

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Related: gamedev.stackexchange.com/questions/40615/… \$\endgroup\$
    – House
    Jun 27, 2013 at 17:26
  • 1
    \$\begingroup\$ Dont forget to look at pid control en.wikipedia.org/wiki/PID_controller this prevents unnecessary fluctiations(temporary unstability) or unnatural targetting. \$\endgroup\$ Jun 28, 2013 at 10:48
  • \$\begingroup\$ A more general solution than those given here is to recognise this as an inverse kinematics problem. While these methods involve some 'more serious' math, they are well studied, can solve for many constraints (engine min/max outputs, 'favor' certain engines), work in 'n'-dimensional space (2d, 3d, pivoting engines, thrust deflectors, mobile masses) etc. \$\endgroup\$
    – sdfgeoff
    May 16, 2021 at 12:25

2 Answers 2

6
\$\begingroup\$

Lets imagine the simple situation of a ship with just one engine. In order to move the ship, we simply point the thruster away from the direction we want to go, and thrust out. That pushes us in the direction we want to go. It's not possible to rotate a ship composed of only one thruster.

Lets scale our ship to three engines to make it more interesting:

enter image description here

If we wanted to move this ship somewhere up and to the left, we'd just point all our thrusters in the opposite direction and fire:

enter image description here

Same solution as the single thruster that takes care of linear movement.

But what about if we're missing a thruster? We have an unequal load?

enter image description here

Following the same strategy will cause the ship to rotate. In many situations, this will be mostly unavoidable, and in some cases preferable since it will orient the ship for better use of the available thrusters.

One strategy for mitigating this would be equalization. Split the ship down the axis of desired movement:

enter image description here

Then ensure that the right side and the left side equal each other. If they don't scale the thruster output until they do. This can easily result in no thrust being applied. It's up to you to decide if you want to instead thrust out causing rotation or force the player to redesign their ship by re-organizing their thrusters.

How about rotation?

This question describes the idea very well.

enter image description here

You'll need to calculate the center of mass. Then calculate the torque provided by each thruster. Lucky for you, your thrusters rotate, so you can rotate them to provide maximum torque. Maximum torque will come from a right angle to the moment arm. Applying the sum of the torques will rotate the body around the center of mass. You can also choose some other arbitrary rotation point like the bridge of the ship.

If you want to ensure that you rotate in place you can scale back the thrust of the thrusters that will cause your ship to move linearly. You can do that by adding up all the thrusters that have a positive torque and all those with a negative torque, then compare their absolute values. The group with the larger absolute value should be scaled back to match the absolute value of the other group.

You may also find a very helpful resource in Amit Patel.

enter image description here

He's done a 4 part series on configurable space ships here: part 1, part 2, part 3, part 4

\$\endgroup\$
1
  • \$\begingroup\$ There are other (more elegant) solutions to this. But ideally, if the player creates good designs, these strategies should work. This answer is only meant as a basic starting point for this kind of control. There's lots of room for improvement. \$\endgroup\$
    – House
    Jun 27, 2013 at 18:50
-5
\$\begingroup\$

I am solved that with local search. It's working, but performance is nearly bad. Maybe it is better to use theoretical mechanics but I do not know it.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ -1, that's a very vague answer. Can you explain more what you actually did to solve the problem? \$\endgroup\$
    – House
    Sep 6, 2013 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .