Jump to content

Need help with trajectory prediction for my 2d space game


Motorsheep

Recommended Posts

Yeah, so I would have liked to post this in the Addons section because I'm looking for help from coders and/or math geeks, but since it isn't really KSP-related, I decided on this place.
Mods, please do move the topic if you feel it would fit in a more specialized section.

 

Anyway. Here goes:


I'm making a little 2D arcade space game that basically puts "Lunar Lander"-like elements in a tiny solar system with orbiting planets and moons. 

Fuel efficiency is obviously going to be an important gameplay point, and so I want players to use gravity assists etc. For that, I need to be able to show predicted trajectories. And that's where it gets complicated. 

I'm using Game Maker, and the tutorials, discussions or even marketplace scripts that I found on the topic rely on Game Maker's built-in physics. And those don't help me because obviously I don't have a constant "down" direction for gravity to pull in. 

I've only got relatively basic skills in GML (and I know even less about other languages) and while I'm not exactly sh!t at maths, high school was a long time ago. 

So I'm looking for help creating (or finding somewhere in the GM marketplace) something that will allow me to graphically display a projected trajectory. Since I'm not using GM's built-in physics, so far it's all just simple vector addition (current veloctiy + sun gravity + current grav-well gravity). But I have no idea how to draw a prediction, since my gravity direction changes constantly, and I have multiple sources of gravity AND distance thresholds at which they become active, like SOI's in KSP. Somehow I think that a frame-by-frame prediction of next x and next y over thousands of frames would kill most computers running this game.

 

So. Is there anyone out there who...
a) can point me to someone who knows this kind of stuff (the person/people who made MechJeb maybe?)
b) can help me find something on GM Marketplace that would do the trick
c) can help me directly with coding this
d)  ...has done this before and could help me port it into GML?

Thanks very much.

Edited by Motorsheep
Link to comment
Share on other sites

2D means you only have four quantities instead of six. Could be Cartesian position and velocity (useful over small distances) or Keplerian (useful over large distances within a single SoI). If you go for Keplerian, you'll expect conic sections with a focus in the parent body. You can use patched conics to blend the conic sections across SoI boundraries, which are defined by a(m/M)^⅖ where a is the semimajor axis and m/M is the ratio between the child and parent bodies. I'm not quite sure about the transformation between Keplerian and Cartesian, but I know there are resources. If you adapt the 3D to the 2D, just zero out inclination and LAN should follow.

Link to comment
Share on other sites

Yeah okay those terms did ring a bell but... Jesus Christ where do I even start?

As to the distances... they're going to be VERY short. Planets are close together and they're tiny and dense, and gravity falloff is accordingly fast. You can basically reach escape velocity from Earth in a matter of two seconds of full thrust. Stable orbits around moons are just about doable, but no more than that.  They won't be a big part of the gameplay.
(Currently, Earth is only about 80 times larger than the player ship is tall, and the whole solar system is 60 times "Earth"'s diameter, but that's probably bound to change a few more times as gameplay elements progress).

 

Anyway. The basic approach would be to create a coordinate system relative to the SoI's position and then plot a function displaying my current orbit with the help of Kepler's laws?
I've skimmed over the Wikipedia article on Kepler orbits.. Gotta say... This looks a whole lot more complicated than I hoped :P

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...