Hello!
Ive been stuck on this for days now, nothing I have tried works properly.
For a space conflict game I need to work out how long a ship should accelerate for to reach a destination bearing in mind it has to turn around and then decelerate.
Ive tried various calculations ad methods but nothing gets the ship to stop at the right position.
The infomation I have to work with is:
Acceleration (will vary on the ship)
Starting Position
Target Position
Time Taken to rotate (will vary on the ship)
I also need some help making the ship turn as if it were using thrusters, the rate of turn increases until it is half way then the rate decreases ntil the ship is facing the right direction
Please , if someone knows how to work out how long the burn should be so that the ship will arrive at the target with 0 speed (or as close to 0 as possible)
Regards,
Someone who is absolutely lost for what to do,
Theo
Hi, what you are looking for are the kinematic equations. You will probably need to work something out for the rotation time yourself, but you can use them to calculate the acceleration times and so on. Have a look:
What have you tried and how has it failed? Maybe its easier to fix something existing than create it from scratch.
Are you using rigidbodies for this or do you simulate it yourself?
If the acceleration stays the same (ship not getting lighter due to emitted reaction mass) accelerating and decelerating should take exactly the same time (green and red are equal in your drawing). Then just subtract the time the ship needs for turning.
Why not make it easier and just use a single “push” for rotating with a constant speed? Have a look like Space Shuttle or Sojous turn around. Why do you need it firing the thrusters all the time?
Just as an example, to get you closer to your goal using the kinematic equations:
Assuming your rotation was instantaneous, you simply had to calculate the time you needed to accelerate for half the distance between A and B (which you can do given the start and end point, as well as the acceleration), then flip around and accelerate into the opposite direction. This would make you arrive at your target destination with a velocity of precisely 0m/s, after an amount of time exactly 2x the time you calculated for accelerating.
What’s introducing a bit of a problem here is your turn time. So let’s imagine you need to travel 10 seconds with instantaneous rotation, meaning 5 seconds of acceleration and 5 seconds of deceleration. So a simple approach would be to say, ok we need to start turning (turnTime/2) many seconds before reaching the halfpoint, meaning for a turnTime of 2 seconds, we accelerate 4 seconds, then turn 2 seconds, then decelerate 4 seconds. However, now we spent 1 second less accelerating, so our topspeed was lower and thus the travel time was longer. Knowing this, we’d start turning a little bit later and so on. You get the idea. There is probably a precise mathematical formula to calculate when exactly we needed to start turning, but i cant think of it right now. Anyways, after you have the precise point or time at which you need to start turning, then the rest is really easy to derive, since it’s basically just the time needed to reach that point, plus (turnTime/2) and then multiplying the entire thing by 2 to get the full travel time.
Yeah. I see what you mean. I did try have the ship actively checking whether it should begin the turn based on :
Is (my distance * 2) + (time it takes to turn * current speed) < distance I have to travel (origin → target)
I might try have it actively check and then make sure it won’t undershoot by making a minimum speed and having it smoothly translate to the point if the minimum is reached.
And if it overshoots just then thrust forwards to a slow speed then stop using RCS thrusters.
Probably more realistic to not land on your target dead on each time. Especially if your hastily planning maneuvers in combat conditions
You can solve this with calculus, where the distance traveled would equal the piecewise double integrals of acceleration and deceleration plus a constant distance traveled during rotation. The subscript “t” time spent accelerating and deceleration in the integrands is the variable you’re solving for.
However, I would recommend just faking it. Do not use Physics to achieve this, because your solved time will still not give you an accurate result. Use a sequence of tweens. DOTween has good support.
Off-topic, but generally you just reply to someone, delete what you dont need and thus, for example, only answer to a specific question. Then repeat the process if you want to reply to more than one thing the other person said.