Issues with your account? Bug us in the Discord!

Physics question -- how to steer a starship -- Take 3

croxiscroxis I am the walrus
lets pretend that you are playing a top-down tactical space ship game with Newtonian physics. You can click on the screen and your ship will turn to face that direction. Your ship has a mass and a maximum torque that the thrusters can put outt.

I figured out a method to apply the torque to a ship that is not rotating, but I can not figure out how to do it for a body that already has an angular velocity. So I am poking you very smart people to point me (pun intended) in the right direction.

For the curious the game engine I am using is Panda3D and the physics engine is Bullet.

Comments

  • BigglesBiggles <font color=#AAFFAA>The Man Without a Face</font>
    Just add the additional velocity from the newly-applied torque to the current value. Use vector algebra.
  • Random ChaosRandom Chaos Actually Carefully-selected Order in disguise
    Is this (1) rear thrust, pushing the ship forward or (2) rotational thrusters to change the angular velocity?

    I'll have to do some thinking on (1).
  • C_MonC_Mon A Genuine Sucker
    I don't really get what the main issue is, might be because I'm stupid ;), but I agree with biggles. :)
  • JackNJackN <font color=#99FF99>Lightwave Alien</font>
    Are you worrying about the maximum Torque value?

    I agree with Biggles because he has no face.
  • Random ChaosRandom Chaos Actually Carefully-selected Order in disguise
    As for Biggles' answer, I think what Croxis might be asking is if you have a spinning ship getting rear thrust, how do you add in that thrust over time since the direction of thrust is constantly changing. Simple answer is you need to integrate the thrust over time. For a computer program, this becomes slightly more complicated since we are not talking about raw thrust but rather position of the ship, which will be affected by the thrust at each timeslice. I would think the easiest way to do it for a program would be to choose the average angle during each timeslice (program loop), apply thrust on that vector, and calculate new position and momentum. Repeat for each new position. This gives you a near approximation of the true result, and should be more than sufficient for writing a computer game though not good enough if you require a perfectly real simulation, which would take a bit more math and CPU power.

    Hope this helps!
  • BigglesBiggles <font color=#AAFFAA>The Man Without a Face</font>
    He said torque, so I assumed he meant thrusters for controlling direction. If he means force then what you said. :)

    Also, [URL="http://www.amazon.com/Physics-Game-Developers-David-Bourg/dp/0596000065/ref=sr_1_1?ie=UTF8&qid=1360892909&sr=8-1&keywords=physics+for+game+developers"]this[/URL].
  • croxiscroxis I am the walrus
    Sweet. RC, I'm not factoring linear velocity, just rotational.

    A little more detail: I'm working on a primitive navigation AI for ships with a predefined maximum torque (which can be increased or decreased by power levels, damage, etc but I digress). When the AI is given a desired heading and rotates the ship to point in that direction. In a simple example the ship has a heading of 0 and no rotation. The AI is given a target heading of 90 degrees. The AI then puts the torque to 100% until 45 degrees, then torque is put to -100% and the ship stops rotation at a heading of 90 degrees.

    The problem I have is calculating when the switch to breaking should be.
  • BigglesBiggles <font color=#AAFFAA>The Man Without a Face</font>
    When to switch to braking depends on how long it takes to stop rotation from the current angular velocity (which can be calculated from that and the maximum available torque). t = w/a. Using this value, you can figure out how long to turn at full angular velocity before applying the braking thrusters.

    Based on this time value, you can calculate how far the ship will rotate during this time. T = ut + 1/2*a*t^2. (Excuse the T for theta; I'm too lazy to grab the correct symbol.)

    Now that you have the distance required to bring the ship to a stop, you can calculate what direction it should be pointing when braking should begin.

    You may have noticed that these equations are like the linear velocity equations with different symbols; that's because they are.

    Assuming I've got my basic physics right and haven't just made all that up, you should be able to do what you want using those equations. :)
  • BigglesBiggles <font color=#AAFFAA>The Man Without a Face</font>
    By the way, you might find that a well-tuned PD controller will give better response than absolute calculations.
  • croxiscroxis I am the walrus
    The most boring 1 minute video of an untuned PID controller of your life: [url]http://www.youtube.com/watch?v=ZQfKZ-G8BOs[/url]
Sign In or Register to comment.