- Home /
When should a newtonian spaceship start slowing down?
I'm working on a 2d (top down) spaceship shooter with newtonian physics. I'm having some trouble with the ship AI though.
I want it to begin to slow down when it is nearing it's target, the trouble is, how does it know when to start slowing down? I guess it would be a factor of the mass of the ship (no drag), the velocity and the maximum reverse thrust (applied via rigidbody.AddForce(transform.right (-maxThrust Time.deltaTime));).
Sorry for the maths problem :-)
Well, yes, it is just a pure math problem. Nothing to do with Unity, or really with games.
Correct answer: for a game, do whatever makes it the game "feel" right, and ignore how it really would work. If you want it to "feel" real, just pick a distance from the space station that looks good, and 3-8 seconds of fake slowdown (based on pilot skill, since that's fun.) Consider making it an easy $$anonymous$$i-game.
$$anonymous$$ath answer: It's the same as tossing a ball in the air (tilt your head sideways.) Gravity is like the reverse thrust. That's a known equation. Let H be your stopping distance and solve for G.
I tried making up average slow down distances and they would work fine until you applied it to ships of different mass and thrust.
The answer below worked, now I can just add a random modifier on the distance based on how difficult the current AI should be.
Answer by Kavorka · Apr 04, 2014 at 03:14 PM
I derived the formulas. They are:
distance = velocity^2 / (2 * acceleration) or
distance = velocity^2 mass / (2 thrustForce)
That worked brilliantly!
$$anonymous$$athf.Pow(forwardVelocity,2) * rigidbody.mass / (2 * thrust);
When my ai reaches that distance from its target it now begins to slow down and stops pretty much exactly on target.
Your answer
Follow this Question
Related Questions
Calculating the perpendicular direction an AI ship needs to face to fire its cannons? 2 Answers
AI reflect shooting 0 Answers
Advice on my Ship AI... 4 Answers
Determining thruster activation on 3D spaceship 1 Answer
Enemy strafing AI Top Down 0 Answers