We will cast rays from the camera
then pick the object which they collide with.
Save the camera as its own scene
In the RayPickerCamera scene
add a RayCast3D node as a child
Attach a Script to the RayPickerCamera node
for access to the RayCast
Capture the current position of the mouse
Multiple by 100 to capture anything within 100m
We will now set the target position
of the ray to the projected local ray normal at the mouse position
Also force the ray to update so we get the current position
Now we need to check if we are colliding
then store what we are colliding with
If the collider is a GridMap
then we want to access the cells
We don't have access yet so for now we pass
To gain access to the GridMap
Make it available as an export variable
Now return to the BaseLevel scene
Choose the RayPickerCamera node
In the Inspector assign the GridMap
Now that we have access to the GridMap
We can find the point in the grid
at which we are colliding
To interact with the gridmap
add a new Input Action for
set the action to left click
If the ray is colliding with something
change the cursor to a hand
If the collider is the GridMap
check if the current cell is empty
change the current cell to a red one
otherwise change cursor back to arrow
full code shown alongside