DotNetMud: SpaceGame: Autopilot

After an aborted run at Rares Trading in Elite Dangerous (idea: pick up rares, go to Fehu, sell them, and then pick up missions there.  Problem: takes many hours to get enough worth selling), I took a look at writing an autopilot in my javascript space game (the part that is not yet Mud-like, but I intend for it to be).

Nice: Javascript has a Math.atan2(y,x) which _possibly_ avoids the x=0 problem that normal Math.atan() solutions do.  (arctangent gets you the angle to something so you know where to point the ship).

However, my code doesn’t work.  My ship very often points AWAY from the target, and applies FULL THRUST FOREVER.  This is NOT how you go somewhere.

There’s another aspect – I’m simulating “keyboard control”, ie, IsThrusting, IsLeft, IsRight.   For the ship to feel responsive when playing the game, need to have good numbers for these.  But with autopilot, there’s a lot of jigger (LRLRLRLR) because it continually overshoots its target.

So, here’s what I have to do for the relatively final solution:

  • Set up the ship so that there’s a finer gradient of control.
    • What I’ve seen other games do is, the longer you have it pressed, the more thrust you get, up to max.
      • This means I need to swap out my current keyboard handler (keyup, keydown) to change to a dictionary of “when was it pressed”, so that I can calculate how long its been held.
    • Or, I could go with W = 12.5% thrust, Ctrl-W = 25%, shift-W= 50%, and ctrl/shift = 100%.  Almost 8 stops.  More instantaneous full thrust available.
      • I want to avoid something where the autopilot can take a shortcut that’s not really available to a player.   So if I did the slow build up, I’d have to have the autopilot also do a slow build up.
  • Change how I do the maths for the autopilot.   Inputs to autopilot:  Who to go to, and what distance to orbit them at when we get there.
    • I see a few major layers.
    • First one is “close the distance”.   This would use the calculation of … http://physics.info/motion-equations/  … ouch, my brain hurts.   Basically, I need to find a solution for:
      • If I start at the orbit distance, and accelerate away at 75% thrust, what velocity am I at when I get to my current distance away?   Reverse that.  That’s the velocity towards the object that I want.   Call that V1.  I want it to shut off as I get close to the destination so that orbital stuff can kick in.
    • Second one is orbital force.   Skip this if I’m more than 2x the desired distance.
      • Figure out if I’m going clockwise or counter clockwise from the destination.  OR, just assume one direction for now.  clockwise.
      • Figure out the vector I need to be in a perfect circular orbit around the object at the desired distance.   Magnitude is known (previous post on orbital mechanics has link to the article), and Direction is 90 degrees from where the destination is.
      • That’s my desired vector V2.
    • Combine V1 and V2.  This is my desired vector V3
    • Look at my current vector V4 and figure out the change that needs to happen V5 = V3-V4.
      • Do a left/right thrust as needed to point me at that vector (do a smoothing function here).
      • if I’m pointing in relatively the right direction, do a thrust along that vector (do a smoothing function here).

This could be really fun.

Image: wikipedia

Tagged with: ,
Posted in Code, Games

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories
Tags
.net 3d 3d-printing 4k abc15 algorithms ames android anonymous types asp.net audio editing aws backup basecamp beatunes biorhythm bitcoin bittorrent blender blog boston marathon bpm c# caffeine campfire candycrush car carmax charity chiropractor cities-skylines clog clone codelouisville codepalousa coding coffee collaboration color run ComputerElbow ComputerVision configuration consulting cooking crash course crashplan crestwood cycling dabda dan dapper DataSet ddl diabetes dictation dotnetcore dotnetmud downtown e-cycling elite excel exercise expiration facebook feature-branching firefall flipflops Flow FL Studio focus food forecastle fortresscraft franklinplanner gadgets game-design games git github google docs google maps gopro gps grandpa greenshot hack half marathon headless health heart rate hiren ignew integration testing interop inventory ios ipad itunes javascript jobs karma kdf keyboards keys kittens lamont laptop lavalamp lego life lifehack linq linqtotwitter linux los angeles louisville mandelbulber massage therapy mastery-teaching maths merge metformin Minecraft miniature modeling monitor mud muhammad ali institute music mvc mycartracks netfabb nexus10 node nostalgia nutrition nwipe oldham county grand slam opal openjscad openscad owin pacedj paper mockup pepakura performance photoscan politics pomodoro postgresql powershell premiere prius process product-management project-management qa ReFS resharper review rmi roman road 5k RSI rubiks running samsung 700t sandals schedule scooter scribblelive selenium service shapeways sleep slic3r sneakersync snot software software-engineering solidoodle soylent spacegame speaking sql sqlite SSDT SSIS standing state-machine stayfocusd stonehearth sunset tablet teaching team teamcity teamtreehouse terraform tesla testing tfs time timelapse torque touch tracks trs80 Tuple tutor twitter ubuntu unit testing utilities video video editing visual studio vscode vsvim warp stabilizer windows 8 windows home server wordpress wpf xml
Archives
%d bloggers like this: