Hi, I've been working on a procedural terrain generator for a little while and it's coming along nicely. I'm at the point where I'd like to spawn grass patches across the land, but I'm struggling with the logic.

The terrain is a flat surface made up of several bumpy squares combined in an ArrayMesh. I'm looking for a method that can check if the random space I'd like to spawn something in on is flat ground. I'd check the given x and z coordinates and see if the y value of my mesh is 0.

I watched this tutorial ( ) and it seems like it would accomplish what I'm looking for. There's one problem, though, and that's that to pass the height information to his shader, he supplies the height map that made his terrain. I'm not sure how I'd get the height data of my ArrayMesh to be understood by a shader, or any object wanting to understand if there is ground beneath where it's spawning. I'm pretty new to 3D, so any suggestions are greatly appreciated!

    Sushibee175 Vertex shader already knows the elevation (and inclination for that matter) of every vertex it gets at input. If you need it per pixel, just pass it from vertex shader to fragment shader via a varying variable.

      xyz Ah, I see. So if I understand correctly, I can apply a shader to the ground and have it spawn in grass based on the y of the specified point. Follow-up question, though: is there a way to access that elevation outside of a shader? Say I wanted to spawn a character in at a random point on the stage, but need to check the point's elevation in GDScript - is that information available outside of a vertex shader?

      cybereality My grass wouldn't be several thousand blades, but just a few scattered meshes representing little clumps. If it runs at _ready, it shouldn't be too bad hypothetically.

      I also thought maybe I could export my own "height map" that's just binary black and white based on the top of my mesh. That could be a way to determine "legal" space. Definitely open to hearing any other methods, though. I'll spend today experimenting with what you two suggested. Thank you!

        Sushibee175 I also thought maybe I could export my own "height map" that's just binary black and white based on the top of my mesh.

        That would be called a (1-)bit mask.

        xyz
        cybereality

        Thank you both! Ray casting was definitely the solution. I feel like I've just unlocked a very powerful tool for the future. I had to create a child node with a CollisionShape of my ArrayMesh, but it wasn't too cumbersome. I'll tidy it up in the future to make it faster.

        Warning to anyone who reads this in the future: when I tried to check "position.y" from "intersect_ray()," it took me an hour to figure out why the y value was not equal to 0 despite displaying as such. Turns out, Vector3s are kind of stored as strings in dictionaries (which intersect_ray returns), so I had to write if str(variablename.position.y) == "0" instead of if variablename.position.y == 0... that might let you avoid the headache I just endured!

        I don't think Vector3's are stored as strings. The components should be floating point values. But they are not exact, so you should check within an epsilon.

        var epsilon = 0.01
        if abs(your_var.position.y) < epsilon:
            # they are close to zero