Say I have an actor who needs to get from point 1, to point 4 but they MUST follow points 2 and 3 to get there. How i do?
Currently I have a road system where you click to place road points down and they connect to the previously placed point.
All points are aware of their immediate connections like so:
So back to the main question. How do I tell Bob he must follow the connected points to reach his next location? I imagine its kinda like A* Pathfinding, but with only certain points Bob can go.
To plan those paths manually its not complicated code:
Make struct that is:
something that identifies path, like starting point and ending point. Let it be 2 integers
then array of integers for actual path
When actor needs to go from A to B, you select one of predefined paths. So you get from array in struct integers that represent points. Then read next point, gets its world location and follow.
That is for selecting and playing path to follow.
Now how to make points:
create actor that is “nav point”, add to it some marker like red mesh or billboard or just arrow component
that actor should have exposed to editor variable, that is integer index, sadly you should set that index manually, constructor script does not guarantee they (index numbers) will not change.
so now you have nav point actors, each has >UNIQUE< index. You can set up path by adding indexes to array in struct.
Next step would be combining 2 different paths to move from A to B then B to C.
And next next step is finding optimal (shortest) path. But that i think needs some graphs traversing etc, so probably C++.
If those points do not change in RUNTIME you should make/calculate paths only once at begin play.
However if level is premade (ie. not proceduraly generated) you can create optimal paths manually in editor.
Its a city builder game, the roads are made at the player discretion. In testing with 50-100 cars it doesnt seem that theres much lag. Will see how it performs with more later.
Oh for city build game, you definitely need C++ to create navigation.
Also depending on how many cars actors you want on street, you may need to optimize it heavily. That means you fake traffic not simulate it. And best would be something like niagara, to move cars on street so it looks like traffic.
I am working on game that has lots of actors moving but in space.
What i found out (and what failed):
using niagara and instanced static meshes, Tiny instanced static meshes look bad. Well maybe that can work for cars. But we were able to move around 20000 of such meshes, in c++ on tight loop.
using niagara and particles (transparent ones so overdraw was heavy), that got down to 5000 objects
now we are using actors with single emmiter each, we got down too 2000.
Anyway if this is for cars that are visual only (not gameplay), just fake traffic do not bother with paths navigating. Else expect around 1000 maximum.
And there is whole MassEntity plugin in matrix city demo. Look there.
And describe scope of game whet you need this pathing for.