I’m trying to find a way to procedurally lay down a path, road and/or fence as a function of the game. Think Simcity roads/zoning or Tropico roads/paths. The same logic I would use for putting down a fence line like in AoE or command and conquer. Essentially I want the player to select a mesh/actor, click in a space, drag the selection to an end point and release the button to lay the mesh over the entire drawn path/area. I’m hoping to accomplish this is blueprints if possible, I’m not good enough with C++ yet to accomplish it otherwise. I know it can be done using construction script but that is for level building pre-play. Any help and advice would be much appreciated!
The same code that works in construction script also works in the normal event graph.
While Zeustiak is correct in that the same code works in construction as it does in event graph, there are some differences to them both. If you mean in example just making a variable called RoadLength public will give you a nice slider you can use in the editor to make the road as long as you wish, if that would work in the game aswell, yeah it will, however since you don’t have any easy way to change your RoadLength while ingame, to get the result like in simcity in example, you would have to create some sort of an UI that would change those values for you.
As for advice, I haven’t done this myself yet, but just thinking outloud, You would need a way to chose what mesh to use, through UI, have them displayed somehow, then probably use the handy ConvertMouseLocationToWorldSpace node to detect where you first clicked and place the initial road mesh there, then let’s say you want it like in those sim games to continually show you the mesh and rotate it to where your mouse goes so that you can align it etc, you could do that in a Tick event, constantly get the mouselocation and use the same node to find the location in world space, then you could maybe do a findlookat rotation from where you first clicked and where your mouse is now, feed that rotation into the mesh you placed to make it rotate towards the mouse. Lastly to create a road from one point to another you would again get the location of where you first placed the first road mesh and the location where your mouse is now, using the same technique with ConvertMouseLocationToWorldSpace subtract the first location from the current mouse location, this would give you a vector, you could then get the length of this vector and divide it by your road’s length to determine how many road mesh pieces to spawn.