- Home /
How to make drawable Paths
Hey! So I am making a Village/Kingdom simulation game but am having trouble on how to make paths that you can draw. So for example you click the path tool and draw a big path then draw a smaller path heading another angle. I also am not sure how to make buildings need to snap to the path so they arent in the middle of nowhere. I have my GUIScript and BuildManager script if you need them just tell me. Thanks in advance
That's a BIG job.
To do it, you've got to create a fairly complex UI, create 3D models on the fly (if you're putting the path on TOP of your terrain) or modify the existing terrain (if you're adjusting the terrain itself), do work with terrain colliders to figure out where the mouse is pointing in your world...there's a lot to be done.
Perhaps you'd be better off looking at the Asset Store to see if there's something already on there? You may be able to browse its code to see how it's done.
Alternatively, break the problem down into manageable pieces and ask for help on those. I think that here you're asking for someone to write a large piece of your game for you.
I dont think there is anything. Whenever I look for what I need it will come up for pathfinding and I cant find anything that will work (Preferably free).
While @IgnoranceIsBliss is sort of correct if you don't know how to write a A* algorithm, instance prefabs, generating along a spline you're going to have a bad time. If you know how it's super easy but will take some time.
You're going to want to create your path logic first, this can be achieved by instancing markers / nodes in world, once you have those instance nodes and if you want to have AI follow the path you need to implement A* along those nodes.
Hey! Sorry for the late reply, I dont meen pathfinidng quite yet I mean a path that people walk on similar to this: https://www.youtube.com/watch?v=-saoX0hxJ3E Thanks :)
$$anonymous$$ake a 2D array of textures, each one represented by grass, the squares you click on become dirt.
int tiles[100][100];
for(int i = 1; i < 100; i++){
for(int j = 1; j < 100; j++){
tiles[i][j]
}
}
As I said, huge job.
But I'd start with learning how to create a mesh at runtime, since you'll probably want to build your paths as a 3D object that you draw on-top of your terrain.
To construct the path, you'll want to put verticies every 'x' units (depending on the resolution your game is presented at) on either side of your path (create a list of Vector3s), attach them together to form triangles (a list of Ints), and UV-map them correctly (a list of Vector2s). Wrap them all up in a $$anonymous$$esh object and set the $$anonymous$$eshFilter.shared$$anonymous$$esh property of your GameObject to the newly-created path mesh.
As the algorithm gets smarter, you'll want to make the number of points-per-unit adaptive - when the path is straight you only need a couple, when it's curved you want a lot more.
The points on the path will have to be positioned so they don't fall under your terrain - this will most likely need you to fire a ray from above to the positions where you want to place your verticies - that will let you know what height to place them. You may want to tinker with the ordering of your shaders too, so that your path is drawn after-and-on-top-of your terrain, just in case some terrain triangles try to poke through your path.
Start all this ignoring height - just get it running in 2D first before you bother dealing with height and the terrain.
This is just the first step of the process though. I'd make sure you're quite comfortable in Unity before tackling the problem.
Your answer
Follow this Question
Related Questions
Making Building Placment rotatable 0 Answers
Making Building Placement Buildings rotateable 4 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Objects Stuff 1 Answer