How do I decelerate a spaceship to hit it's target?

  • I have a spaceship, viewed from above. I want it to turn towards it's target (done that part) and then speed up (done that part) to a maximum speed and then slow down so that it lands on (or near) it's target. It will have different deceleration and top speed values, so it needs to be done mathematically rather than tweaking numbers in my code until it works.

    So the trick is to work out the distance at which it begins to decelerate. I've checked a few posts on other forums but haven't got any of them to work. Anyone have experience of this in C2 or know how to get it working?

  • Might try line of sight.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Did a little googling

    Time to decelerate to zero:

    time=(speed/deceleration)

    For example if current speed is 900 and deceleration 300px/s, then you need 3 seconds to stop the ship.

    Formula to calculate the distance:

    Distance=deceleration*(time^2)/2

    So to stop at target you need to start deceleration at distance 300*9/2=1350px

  • Here's an example...

    https://www.dropbox.com/s/6fumfmxyyb6bq ... .capx?dl=1

    Click to add a vehicle with random speed and decceleration. It will calculate the braking distance to stop on the white line and apply the brakes accordingly. The equation you're looking for is the one used to calculate the Braking Distance.

    [EDIT] If you want more precision, just remove all floor() expressions. I added them just because I needed the numbers to fit the text box on the vehicle. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Hope this helps. Cheers!

  • Thanks guys, cracking stuff

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)