Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
2  
Related: gamedev.stackexchange.com/questions/40615/… –  Byte56 Jun 27 '13 at 17:26
1  
Dont forget to look at pid control en.wikipedia.org/wiki/PID_controller this prevents unnecessary fluctiations(temporary unstability) or unnatural targetting. –  huseyin tugrul buyukisik Jun 28 '13 at 10:48

2 Answers 2

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

share|improve this answer
    
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. –  Byte56 Jun 27 '13 at 18:50
up vote -1 down vote accepted

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.

share|improve this answer
2  
-1, that's a very vague answer. Can you explain more what you actually did to solve the problem? –  Byte56 Sep 6 '13 at 19:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.