0 votes

I am making a 3D isometric game and I want the tile underneath the mouse to have a border highlight on it, like this: https://pasteboard.co/JVHYrvL.jpg

The solution needs to work no matter the location or scale of the tile as the camera can pan and zoom. I previously had a rectangle poly I moved over the tile the mouse was over but there must be a nicer way like a shader or 2D UI drawing

in Engine by (134 points)

1 Answer

0 votes
Best answer

Get the position the mouse is over using ray-casting from the projected position of the camera/viewport.

Compare that position using GridMaps world_to_map(position)

Now you have a few options here

  • Draw directly to the map using a mesh_library
  • Use an upward facing Quadmesh MeshInstance with a Texture
  • Unproject Line2D or a CanvasItem's drawn Rect2D
  • Use a shader like you mentioned

If you do decide to use a SpatialMaterial with an Albedo_Texture like this img which is the easiest method. Ensure to enable Transparency

by (5,020 points)
selected by

I already have the code to intersect a ray, but thanks for mentioning it. I think I will go with a line2D as then I can guarantee visibility and consistent look no matter zoom levels. I will just have to unproject 4 points at each of the corners to calc size (and it's isometric)

That part is actually easy, from the world_to_map() position draw each point diagonally based on GridMap's cell_size

Yup, that was generally my thoughts. From my existing code I already have the centre of the tile in world coords so easy to calc corners from that

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.