I want to know how to pick the correct tile on a isometric map in 3D space. Here is a 2D example.
They use a colour key map to correctly pick the coordinate. How can I achieve this in 3D space? Is the method similar?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
The color picking method you linked is suitable for "3D isometric", depending on how you implement it. This is because 3D isometric is not well defined and can have a similar "ground" as 2D isometric. So the tiles will be the same, what will change is the objects in the world. The objects will be 3D and placed so they fit in with the camera angle of your isometric world. A full 3D world would not technically be called isometric.
If you are representing your objects as 3D polygons in 3D space, the word to search for is “picking”.
Brief summary: A mouse location is (x,y) in screen coordinates. In your 3d world, the mouse location corresponds to a ray (or line) in world coordinates. You intersect that ray with everything in your world and see what it hits. The closest object that the ray hits is the one that the mouse is pointing at.
If all you want to do is know where on the ground the mouse is pointing, it's fairly easy. You intersect the ray with the plane
z = 0. Solve the equation and you get back (x, y, 0) in world coordinates. I recommend doing this even in the regular "2D" isometric world. Color keying tiles on the ground is a lot more complicated than solving this equation (color keying might make sense for more complex shapes though).
If you want to know which of many 3D objects the mouse is pointing at, you intersect the ray with each of the polygons in each of those objects. I recommend starting with brute force: intersect the ray with every polygon and see what hits. Do that first and make sure it gives you the results you want. In practice you'll want to intersect with just a few polygons instead of all of them, using a spatial hash or a gpu buffer with object ids.