🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Space flight - plotting paths and following them

Started by
3 comments, last by LorenzoGatti 3 years, 5 months ago

Hi,

I've been messing around with a strategy game set in space, and have been struggling to get my head around movement. There is a bit of context so please bear with me. There are two main parts to my issues.

---

I wanted to have the player place waypoints kinda like in any other RTS, where the points placed would dictate the flight path, but where that path was constrained by limitations of physics (bigger/faster ships = larger turn radii, and ships have thrust limits), and where ships don't magically stop on a dime like Star Wars. By chaining a series of points together, you would get a curved flight plan showing a ship's predicted path through 3D space. The player would be prohibited from adding any points to the plan that are not reachable within these limitations, and the ship would just fly in a straight line after the end of the plan has been reached - they wouldn't just stop in space. The turns and maneuvers along these paths may be many minutes long - the play space is in real star system scale (let's ignore precision/physics ramifications of the scale here), so there could be big, gradual turns over a large space, for example (important consideration if iteratively solving due to the length of time to solve).

In the past, I created a system like Kerbal Space Program, where you can place 'maneuver nodes' on a flight path, manually adjusting 6-degrees of thrust to affect DeltaV and which will change the flight path's prediction from that point onwards (and the actual flight path followed, itself, if the maneuver is 'saved' into the flight plan and thus used in reality when the ship reaches that point). This works well for one ship, but what about 10s of ships, rapidly putting together flight maneuvers in combat? It's just too much to fiddle with. Hence wanting more RTS-like controls.

Imagine this mechanic of placing flight points ( https://youtu.be/lL8ICX67h9E?t=497 ) except without the very short distance limit (they do it due to being turn based), and where you can just click-click-click and chain them together quickly.

To actually predict this path, I can't see how to do it except iteratively, especially if you want to get complex and have the optional ability to set a target speed at each point (e.g. reduce speed to X at point Y), possibly requiring a ship to flip and reverse-burn (which takes time as well - big ships flip slower etc) as well as speed limits - e.g. here are your points to reach but stay below speed X, as well as a game-wide speed limit to save my poor physics system from dying a horrible death. You can't numerically solve this, no? Having to iteratively predict flight paths for 10s of ships or more - and possibly many missiles - sounds scary as hell. I couldn't see how to instead do this with e.g. splines. I also wonder how to tell if a point is unreachable without doubling back on yourself (i.e. if a point is too close and requires a too-tight turn, obviously you could go out and loop back around, but that is unlikely to be what you want). But again, it sounds like you're gonna have to do a lot of iterative solving as the player moves the cursor and thus changes the target flight point.

---

How do other space/flight games handle AI flight for hitting waypoints? I imagine they're not writing complex flight control systems that apply force/torque to get AI ships to fly through them (I've looked into such systems, and they're pretty full-on). Are they just directly touching velocity? What about the common case of different ships with different characteristics? (Bigger/heavier ship = slower / larger minimum turn radius, etc). I imagine that would be emergent if you actually simulated everything and required a ship to genuinely fight its inertia with real forces. But again… complicated to write/solve and a nightmare for gameplay. I'm familiar with steering behaviours, however I can see some difficulty using them in the above flight prediction systems. If I could wave a magic wand and perform every maneuver as just a series of thrusts, prediction and path following become the same thing (assuming iterative prediction). But that seems like a pipe dream. Advice appreciated - happy to bounce things around.

---

Thanks for any input!

Advertisement


Spaceships can go “straight” very fast (by thrusting forward), or almost anywhere more slowly (by thrusting backwards and sideways and possibly by taking longer routes that allow longer thrust times) and it's important to show speed: close points in space could actually require vastly different flight times (for example, suppose ships are more or less orbiting a planet: some close points can be reached quickly with a sharp turn, but even closer points, below a minimum turn radius, are unreachable with a direct route and require one more orbit).

You seem to be neglecting this temporal aspect of movement in a RTS: the player will often want to move units in the best place they can reach timely rather than in a precise spot sooner or later. I'd expect tactics to revolve around detecting, chasing and intercepting enemies and concentrating firepower efficiently, not around surrounding isolated units with precisde maneuvers or attacking weak spots like in a land RTS.

I'd suggest showing curves in 3D representing planned trajectories (the currently planned waypoints and the segment with the shortest flight time from the last waypoint to the moving cursor) with markers at regular time intervals. Collision courses should be highlighted and/or automatically avoided.

Angles and speeds when reaching waypoints should be unimportant (you can probably assume the player wants to reach a waypoint ASAP) except for special cases like merging two fleets (requires matching speed) or landing.

Omae Wa Mou Shindeiru

LorenzoGatti said:

Hey, I appreciate the thinking!

I do feel like some assumptions are being made - I intentionally didn't go into the design since that was out of scope. Suffice to say, I do think setting a desired speed (from a specified point onwards, which still allows for “get to X as fast as possible” type movement as you say) and other kinds of ideas I presented are definitely relevant to the design I am pursuing.

What I still don't understand is on the flight control side - say I am doing an iterative solve (for simplicity, as opposed to fancy numerical solutions) in order to show the flight paths to the player before they hit “confirm” and actually make the ship perform the maneuvers and follow the path. I can imagine writing a flight control system of some kind, and then doing a lot of iterations to generate the flight path (like a functional/stateless loop using a physics engine + light AI).

It's in the guts of the flight control that I am lost; if I feed in a target location (in the above case, the player's cursor against the plane), how do I translate that into some kind of ship movement that has the ability to be influenced by ship thrust abilities, ship mass/weight, damage, etc? I'm thinking like a seek-type steering behaviour, but those are usually very simple. Would I want to be applying forces and torques to hit my target point? In my experience of past attempts, that is very, very complicated. So let's get simpler - would I want to directly modify velocity, esp. if I wanted e.g. acceleration over time based on mass vs thrust? I've done that before, and it can look very ‘fake’ having objects instantly change velocity to seek their target pos. Maybe it can/should be faked with e.g. ‘max turn radius’ and other kinds of properties that can tweaked per ship? I would prefer not to, but it's an option!

Does my qualm make more sense now? I tried to give context, but let's strip it right back to something simple - advice on how to get a ship with the above characteristics/limitations to fly through target points in 3D so that I can use that for the realtime flight control + for the iterative solve (for previewing the path to the player before execution).

LorenzoGatti said:

Angles and speeds when reaching waypoints should be unimportant

I'm not making an assumption, I mean that if angles and speeds at waypoints are unimportant it's better: you avoid a serious user interface complication (the player picks points, which in three dimensions is more than difficult enough, instead of points, directions and velocities) and flight control AI is less constrained.

Regarding flight control AI, I don't see how physically incorrect shortcuts could be “simpler” than running exactly the same dynamical simulation you use for the actual ship movement. If it turns out to be computationally expensive, you can limit the duration of the flight plans and limit the number of routes to plan (e.g. by grouping ships into fleets that are able to fly in formation).

Instead of painting yourself into a corner with hacks, think of easy to use heuristics that create reasonable and close to optimal paths: regions with approximately no gravity, orbits and gravity wells around a planet, regions where a direct route is optimal or impossible, swerving to avoid collisions in various geometrical cases, slowing down to reduce turning radius, etc.

You can also refine flight plans over time with no need to find a perfect one immediately: given a flight plan, or an ensemble of flight plans, you can simulate some variants every turn to find improved ones. You'd need to simulate flight plan variations every turn in any case, in order to chase moving targets.

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement