How to do Path-finding

Hi. I have a spaceship on a screen which is bordered. I have it flying around nicely. I would like to be able to select a point on the screen and then have the spaceship fly to it. I am currently using the Raycast command to check if platforms are in the way and then kind of fly round them. This works ok, but doesn't produce a result that looks like an intelligent player.

I have never programmed anything like this before. I figured I could use pre-programmed paths, but I would rather write some kind of intelligent program that works out where it can fly in real-time. Could anyone start me off? - how is this kind of thing usually done.

Ideally I want to have the spacecraft fly to a point as if it were a human-player.

Thank you for any help.
iirc there are continuous versions of the A* algorithm, though I'm not sure how robust or easy to code they are. You might try looking into algos used in robotics, that's where continuous pathfinding tends to be applied the most.
Path finding is a non trivial subject. You need to think about whether it is worthwhile putting something better in your game, if what you have at the moment works ok. But if you do want it, I suggest you find some literature on the subject and read up.
I was planning on using the A* algorithm. With that you can still use it in a continuous environment if you overlay your world with a "grid" and then block out the grids that represent terrain. The trick is to get the size of the grid small enough that it accurately represents your smallest terrain feature that can't be moved through.
You can also use A* on 'nodes' instead of a grid. Each node knows which other nodes it can get too, and the costs for going to it. Of course this only works, or works best if you have static objects that you need to navigate around. And you need to come up with an algorithm to place the nodes.
Thank you very much for all the help. I am thinking now of buying a book, since this is a tricky subject. The problem is my scenery - which the space craft needs to fly around will (eventually) be destructable - so new paths will open up and I don't want my spaceship to look stupid by ignoring them.

Yes I was thinking of using a grid - this seemed like a really good solution but then I realised that I have some dynamic objects - which are sometimes stacked on top of each other and partially/completely block routes. They move about as they are disturbed by gunfire or by being rammed into. So I am not sure what to do now. I could maybe do loads of raycasting using the Raycast command to plan a route to the required destination? - I don't know - maybe this will be a bit slow though.

I also had an idea of sending invisible (to the player) sensor objects off to the location and to then record their path so my ship can take the best route. What do people think of this idea? It won't come up with a route instantaneously but it could be worked in.
I will eventually need to think about this too, and was thinking about using raycasts, sensors, and some sort of dynamic grid/node system used for pathfinding that is periodically updated. Not sure how well it will work since I don't want the game exhibiting crappy performance when the scene is large or gets a bit complicated.
A* on a grid works fine for a lot of purposes, but just be aware that the usual A* algorithm doesn't take any sort of kinematics into account, it just assumes direct navigation from grid point to grid point. So if you're doing something like adding forces to your guys to make them move, you'll need to pretty substantially hack the algorithm to make it work right, and this probably means (in part) updating the path each frame and/or modifying cost weights for each cell based on the change in momentum required to get there. For reasonable grid sizes and a decent heuristic, you can probably get away with an update every frame or so, as long as you don't have too many characters pathfinding at the same time. If you do, then you'll likely want to do lazy updates (set waypoints and only update the pathfinding when these are reached or become inaccessible). The more dynamic your geometry, the more you're going to have to update to make sure you don't get blocked...

Whatever you all decide to do, I'd strongly suggest not looking too hard for a perfect solution. You'll drive yourself nuts and you won't actually finish your game. And path-finding is generally not something players will notice at all unless characters get "stuck" (a lot of early SNES games had truly awful pathfinding, and you'd get into situations where you could not move because your "helper" AI player had gotten stuck in a corner because it just tried to follow a line of sight path to you) so as long as you avoid that, you're golden.
Yeah this is one of those things where fudging it a little will work just fine. I've done stuff using static waypoints and they worked fine, it was just a pain to create waypoints for every single map. I imagine it wouldn't be hard to make waypoint maps dynamically and update it periodically as the environment changes. And if that's too slow for immediate interactions (i.e. a giant asteroid is moving towards an enemy AI and the pathfinding can't update the graph fast enough for it to avoid collision), some rudimentary ray casting and/or sensor checking can easily allow AI to at least try to avoid stuff.
The grid approach is definitely the simplest and requires no changes to Box2D itself. One helpful refinement is to divide the grid into fixed-size "zones" (say 16x16 or 32x32), and then aggregate cells within a "zone" into rectangular "slabs". Then use the "slabs" as graph nodes and the boundaries between traversable slabs as edges. Doing this significantly reduces the size of the pathing graph. If something changes, you only have to update the affected zones, not the whole map.

I had tried another approach that aggregated overlapping static shapes into "groups" and stored the convex hull along with any convex corners. A path probe from a start point to an end point did a segment test to see if the path was clear, and if it wasn't, found the group corresponding to the shape and generated path probes to the group points. It worked fairly well for pathing around small obstacles, but required a couple hundred probes to find its way through complex mazes, and sometimes failed to find a path. Since my game project features dozens if not hundreds of AI-controlled units, that cost was prohibitive. It also required modifying Box2D to add support for "expanded" shapes, and only supported polygons. I eventually gave up on it.

Original thread: https://box2d.org/forum/viewtopic.php?t=1531