I have a map inside my UI, and I’m trying to figure out how to make a ship move across it, traveling from city to city. Right now, I’m using the marketplace UI spline, but creating a spline for each route is too much. Is there a more efficient way to handle this? Any guidance would be greatly appreciated!
Can help with this but to have a decent answer.
First this is UI based game, the ship does not exist on 3D world? Is this right?
Do you have C++ knowledge?
I am making 3D game, and the ship only exists in the UI when i open the UI Map —it’s not part of the 3D world. So the movement needs to be handled entirely within the UI system. Unfortunately, I don’t have C++ knowledge and can only use Blueprints
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.
- We need to map image into data where ship can move to and not move to. Swimable NotSwimable
- On this data created we will convert it to a data array.
- We will run a pathfinding alghorithm on this data.
- Show the output as data (line) and move ship.
After this want to give details technically how to do it to get you going.
- We have a map image (I will find something easy from google)
- 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.
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
I honestly don’t know what to say. I wasn’t expecting someone to take the time to provide such a long and detailed solution. I haven’t had the chance to try it yet, but regardless, you have my respect. Thank you!