Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Fly-By-Wire Thrust Control

This topic is 5336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''m building a game, where I want a spaceship whose motion is contorlled by the mouse, at the moment, i simply have its position be your mouse position, but this is not correct, because it is possible to whip the mouse around nearly instantaneously, and the ship''s should only be allowed to move as quickly as its thrusters and the game physics allow. so I''m thinking that i need to have a fly-by-wire system like on modern aircraft; where the user input does not directly affect the vechicle, but instead sets a goal position, which the vehcle then needs to get to by itself. I''m not quite sure how to do this though. to keep things simple, my thruster is always either on or off, and a constant force - no variable throttle or anything like that at first glance, i was thinking that i can simply aim the thruster in the direction of the goal position at all times, and have it fire constantly; but thinking this over, it would just result in orbiting or occilating around the goal position - you accelerate towards the goal, pass it, the thruster flips around, and deccelerates, but you''d end up swinging back and fourth between your origional position and one opposite the goal position so i think i need to have the thruster begin decceleration before i even reach the goal position, but I dont know how to calculate where and when this point is keep in mind that at any given point, the user might move the mouse and reset the goal position, also that the ship is not necessarially at rest initially anyone have any ideas? Thanks

Share this post

Link to post
Share on other sites
Extremely simple would be to use a linear acceleration with a cap:

thrust = distance*constant

if thrust>thrustmax
thrust = thrustmax

This might work, but it depends on your other controls. Does no thrust slow down the ship? (friction) If not, you''ll need negative thrust to get to that position.

Share this post

Link to post
Share on other sites
Have the ship start breaking in when within a certain radius of the goal maybe? And once it''s slow enough, just turn the thrusters off. And maybe zero the velocity(if it''s slow enough the user won''t notice, and the ship won''t drift away).

Of course the radius is depending on the velocity. Something like a linear of quadratic function of velocity. Fiddle around.

Share this post

Link to post
Share on other sites
nope, this is space, so there is no friction, the thruster needs to flip 180 and retro burn to slow down

but i need to know when to start the retro burn, too early and you''d stop before reaching the goal, too late and you''d overshoot and get into occilating/orbiting problems

Share this post

Link to post
Share on other sites
Well, that shouldn''t be too hard. Just thinking aloud here:

position(t+dt) = position(t) + dt*velocity(t);
velocity(t+dt) = velocity(t) + dt*acceleration(t);

Since your thrus is the acceleration is constant, and you want to arrive with velocity essentially zero you should start braking:

velocity(t_end) = 0;
0 = velocity(t_begin) + dt*thrust;
dt = -velocity(t_begin)/thrust;

Now you know how much before you get to the target you should reverse the thrust: dt

But how far away is that?

position(t_end) = position(t_begin) + dt*velocity(t_begin);

position(t_end) is known, zo is velocity(t_begin) and dt, so you can calculate position(t_begin). That''s when you should reverse the thrust. Please note that since I''ve only calculated this formula once here (hence dt could be in the range of seconds) this will not be accurate. It''s only a linear function, and does not take into account that the velocity will become lower after you start braking. You should be able to do that with an integration.

Good luck!

Share this post

Link to post
Share on other sites
with constant acceleration you have (x0...initial position, v0...initial velocity)

x = x0 + v0*t + a/2 * t^2

if you''re braking

x = x0 + v0*t - a/2 * t^2

you want to come to a stop at x1 by starting to brake at x0:

x1 = x0 + v0*t - a/2 * t^2

and the velocity should be zero there:

v1 = v0 - a * t

t = (v0 - v1)/a

put that into the above equation for x1
and you''ll find the position where you have to start braking

if you want to accelerate first and the to break the first thing that comes to my mind isget to equations for the position in accelerating and in decelerating mode and look where they are intersecting.

your current position is x2, so by acceleration you get

x = x2 + v0*t + a/2 * t^2

when decelerating towards x1 you want v = 0 at x1 (at time t_end)

v = a * (t_end - t)

by integration you get

x = a * t_end * t - a/2 * t^2 + c

with c the integration constant; x should be x1 for t = t_end

x1 = a * t_end^2 - a/2 * t_end^2 + c = a/2 * t_end^2 + c

c = x1 - a/2 * t_end^2

so for the position at a specific time

x = a * t_end * t - a/2 * t^2 + x1 - a/2 * t_end^2

now you set the two x positions equal

x2 + v0*t + a/2 * t^2 = a * t_end * t - a/2 * t^2 + x1 - a/2 * t_end^2

t^2 * a + t * (v0 - a*t_end) + x2 - x1 + a/2 * t_end^2 = 0

we solve for t

t = (a*t_end - v0 ± sqrt(a^2*t_end^2 - 2*a*t_end*v0 + v0^2 - 4 * a * (x2 - x1) - 2 * a^2 * t_end^2))/(2*a)

now this t obviously depends on t_end which we do not yet now. let''s say we want only a single solution so the expression under the square root should be zero

t_end^2*(-a^2) - t_end * 2*a*v0 + v0^2 - 4*a*(x2 - x1) = 0

t_end^2 + t_end * 2*v0/a - v0^2/a^2 + 4*(x2 - x1)/a = 0

let''s solve for t_end

t_end = -v0/a ± sqrt(v0^2/a^2 + v0^2/a^2 + 4*(x1-x2)/a)

that should be the time we need to get there...

the time when we have to switch from accelerating to decelerating is

t1 = (a*t_end - v0)/(2*a)

and the position

x1 = x2 + v0*t1 + a/2 * t1^2

let''s check the velocities at x1:

from the acceleration

v1 = v0 + a * t1 = v0 + a * (a*t_end - v0)/(2*a)
= v0/2 + a*t_end/2

from deceleration we have

v1 = a * (t_end - t1) = a*t_end - a*(a*t_end - v0)/(2*a)

= a*t_end/2 + v0/2

so we''ve got the same velocities at time t1 - this will work!
(there would be different velocities if we wouldn''T have chosen the t_end in a way that there''s only one solution for the switching point - it''s best imagine this in a graph with x vertical and t horizontal with the acceleration curve (a parabola with a minimum at x2) from x2 < x0 and the deceleration curve (a parabola with maximum at x0). the parabolas are fixed in size and the second one can be shifted along the t axis (this means varying the t_end value). they''ve to match exactly in one point, if you shift it too far to the right (positive t) there''s no intersection and therefore no real solution for the equation, if you shift it too far to the left there are 2 solutions and you''d have to change velocity instantanously)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!