- Home /
Position of game objects on a hexagonal grid
Greetings, 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
@iilleen_unused I have a project that I must create a Hex map like your map !! Exactly I want to know How you create Hex map On the terrain like that?
Answer by xandermacleod · Jun 09, 2013 at 03:43 PM
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).
but this will only tell me if the centre of the object is intersecting the terrain, not over which hexes the object is (if it's bigger than one hex)
Answer by JoshV · Oct 31, 2013 at 05:10 AM
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)
Your answer
Follow this Question
Related Questions
Making changes to a terrian in game 1 Answer
Vegetation problem 1 Answer
attach Hexagonal Grids to a terrain like a texture 0 Answers