In my project I’m using a normal terrain and a hexagonal map, which is represented by a 2D bool array. I also have an algorithm which converts world position to hex number.
I want to loop for all the scene objects and check if they intersect with the terrain, and over which hexes - to determine if character can move there or not. It’s not a problem for objects with small diameter like a palm, which will most likely occupy one hex, but with bigger objects like rocks, buildings, walls etc it gets problematic.
Pic related, it’s the terrain with hexagonal texture (size of the actual hexagonal map) projected on it.
If any additional data is needed I will provide it. Thanks in advance
I don’t have the code on me, but I suspect you may need to provide information regarding your terrain’s height (in Terrain>SetResolution). The way I would do it (with admittedly little unity knowledge) is to work out where the object’s vector3 position from the corner of the terrain, and then compare it’s Y-position to the heightmap’s value/the setresolution height.
That will only tell you if the object is above or below the terrain though, not whether it intersects. You might require some collider checks for that. You should also be able to cast a ray either up or down from the object and use the hit-info for making a comparison that should work with your algorithm (provided you don’t have multiple stacking objects ontop of each other).
Cheat, and pretend each hex is a sphere or cylinder or capsule? Then you could do something like Physics.Capsule() at the hex’s position and given a radius that would fit inside the hex.
(And I would try to do this on startup for objects that aren’t going to move)