Best Way to Move a Ship Across a UI Map

Understood. No worrries can be done too, however we will walk around the problem a little bit.

I will try to demonstrate how to do it step by step.

  1. We need to map image into data where ship can move to and not move to. Swimable NotSwimable
  2. On this data created we will convert it to a data array.
  3. We will run a pathfinding alghorithm on this data.
  4. Show the output as data (line) and move ship.

After this want to give details technically how to do it to get you going.

  1. We have a map image (I will find something easy from google)

  1. We want to convert this into a data, so how can we do it.
    Option A : You do it manually by hand.
    Option B : You put this image into an actor, get a capture with SceneCaptureComponent2D, set a low res texture target like 128*128 (which give 16384 data points), and read render target raw. If you photoshop image a bit you can get a good data. We can extract if that pixel is swimable or not as data. Use this node to read pixels and convert them to data.
    Image data should be something like below White Swimable, Black NotSwimable. This should be preferable done before begin play in editor but can be ok to do once in begin play and keep that. Since its quite a slow operation.

DataImage

Enlarged Version Of Data Image

As said you can convert this by hand as,
---- Coordinate X, Coordinate Y, 0-1 Swimable or not
or you can read pixels with other method and save them.

3.Now we have to run a pathfinding alghorithm. There is many alghorithms and fundamentally they can be done with blueprints, there are some in code base already however we have to implement ours. I found this while searching.
Also you can use Dijkstra’s algorithm which is slower but easier to implement, found this while searching, also there is some plugins that is done

There is this youtube tutorial based on level generation however its the same so if you implement you can pathfind to ship to the next city.


However all this being said, if your map is loaded you know the ship position and destination. You can always use built in AI pathfinding to calculate splines draw it on map without manually doing it if you navmesh and agents setup correctly. Just mentioning it to put you in right direction. Cause if its a 3d game its a 3d game, you can use engine’s built in advantages. You can basically
Find Path
Get Path Points
Convert them to Screen position

3 Likes