Getting a random point on landscape

I’m trying to get a random point on landscape which is player accessible (walk-able). I’m using a navmesh currently and calling GetRandomReachablePointInRadius with a gigantic radius, but I’m not sure if this is the best way to do this. I was thinking I could use a material, but I’m not sure how I would get a random point (or if I even could). Using a material would be the better solution since I could paint the exact locations I would want the random location generation (within the painted areas) would be, if that makes sense.

Does anyone know if this is even possible using materials (or maybe something else I’m not thinking of).

Example of what I’m going for: Have a resource node (a rock) randomly placed on the map, once the player mines the resource, the resource moves to another random point on the map.

You can get the Physical Material by doing a line trace.

I think there are other better ways of doing what you want. First of all what kind of landscape do you use? custom made or procedural generated? This kind of info helps in finding a solution to your problem :slight_smile:

Thanks for the reply Constantine. After thinking for a bit I also come to the conclusion that using traces would be better then using a navmesh. I’m using custom made landscape and have no plans for procedural.

What I would really want is to spawn said rock only on one material (dirt). If I were to use traces and want it random and to only hit dirt, I would be firing a lot of traces until it actually found dirt.


So there are a couple of ways to achieve what you want that i can think of right now.

First one being the previously mentioned traces on the landscape to find the desired material. You just need a good way to do those traces, not overload the game when the rock depletes trying to find the next one.

The second solution can be “Target Points” placed on the spots that you want the nodes spawned. Using target points you can get the their world location, when the rock depletes find the closest one. If this is done right it can also be very good optimized.

Of course you could have all the nodes inside the game before hand and i don’t know why you don’t do it that way? is this a strategy game? Because you might have to think if the player builds on the area of node and etc. But this is just me thinking ahead.

I could use target points, get the worldlocation of it, then fire some traces in a radius around it. The only problem with that is I would have to place potentially thousands of points, I also don’t want two resource nodes to spawn beside each other, that’s why I was looking for an alternate solution. It would make it a lot more performant using a target point rather than firing traces all over the map though.

It’s a kind of mining game, finding resources around the map. The problem with placing nodes in-game beforehand, is I don’t want the player to go back to the exact same spots.

Yeah having a good trace algorithm can potentially rid of the process of putting target points, also if you make changes to the landscape you don’t have to move the position of the points.

You just need a good way to do the traces, which can be done and not be performance consuming.

Indeed a good algorithm is nice, this is what I was thinking. I could use a bounding box and stretch it over my map, use a hexagonal circle pack within said BB, each circle would be a “target point”. Get all the circles into an array, do a check for x amount of circles around the circles that have nodes in them and exclude them from a new array. From that array you can grab a random circle and it should be good, or that’s what I’m thinking. I still would like some way to exclude spots that shouldn’t have a node.

That got me thinking, could I use the grass paint tool, but instead of using grass, have nothing, but get the location of where the grass would have been?