19 Sept 2020, 21:39

So. That all worked well! I found what triangle my object was in, then used a thing called ’barycentric coordinates’ to interpolate between the three heights of the triangle points to find out the precise height of the land. Here’s a screenshot of the ’get barycentric coordinates’ function.

alt text

It works, and it’s pretty efficient, but only because the terrains are sortof mostly 2d. If you look at them from the top and ignore the heights, they’re just a grid! If I was trying to get these ’barycentric coordinates’ in proper 3d where the points could be any old place, then there’d be a lot more checks and complexity needed, but in this case everything’s cool. See here:

alt text

There he is, standing on one of those awkward corners from before. But properly this time :)