Hello, GullJemon,

Use polar coordinates. Instead of representing a point with a cartesian coordinate system, you represent it with an angle and a distance from a center point (so a random point inside a sphere is just an angle between 0 and 360, and a distance to the center point, ranged between 0 and the ratio of the sphere). Here is a long explanation on how it could be done.

If you where to check if a known point is inside a sphere, you would be just checking the distance between the center of the sphere and the point you are detecting, and seeing if that is less than the ratio of your sphere, correct?

You can think of your hexagon as having two different ratios: A max one when your angle corresponds to a vertex, and a min one, when your angle corresponds to a midpoint.

Now, you imagine that your center point also has a direction, it is pointing to the front. So you can get the look at rotator needed to look from that direction to your known point, and that in turn gives you the angle at which you are in your hexagon.

You know at what angle you are, so you can use that information to lerp between those two ratios to get your actual limit distance at that angle of the hexagon. Then you just check if the distance to your point is lower than that max distance at angle that you calculated.

On a hexagon, you have a vertex at every 60 degrees or PI/3 radians. If you use the modulo operator with 60 as a second input, you will know where you are inside a segment of 60 degrees where 0 is a vertex, 60 is a vertex and 30 the midpoint. You can go from there to calculate the alpha value needed to lerp between max ratio and min ratio. That would be a method of seeing if a point is inside an hexagon.

To get a random point inside an hexagon, you first get a random angle between 0 and 360, calculate your max distance at angle as described before, and get a random float in range between 0 and your max distance.

That is giving you the polar coordinates for the location of your point. You can use those coordinates to get the cartesian world coordinates that correspond to the random point inside the hexagon that you calculated.

For example, you can create a 3D vector that corresponds to the world coordinates position of your hexagon center. Then you apply a rotator to a second normalized vector, with the random angle that you calculated, and you multiply that normalized vector for a float that would have the random distance in range that you calculated (thus getting a vector that points from the origin of the hexagon to your point). You add your first vector to the second vector and that would give you the 3D location of your randomly generated point.

Hope this helps. All the best.