Hello,
I’m currently making a MOBA type game with click-to-move.I have a minimap(Faced down camera with viewport in a corner of my screen) and i want to implement a system that when I click on minimap my player moves to that position, but currently when i click on minimap the raycast goes through the minimap and hits my terrain so the player goes there.I tried to put a UI panel at the minimaps postion to block the raycast but it seems like UI elements cant block the raycast. So any ideas how to avoid raycasting through minimap and how to move via clicking on minimap?
Here is the algorithm I would use to find the location on the minimap:
- Ensure that the top left of the map in the world space is on the coordinate (0, 0), and if it isn’t then alter the other variables to compensate for the offset.
- Create a system to detect if the mouse is above the minimap, and create a Boolean monitoring whether it is. Use this Bool to detect whether the ray cast should go through the map or not.
- When the map is clicked on map, find the distance in the x and the z-axis (Using Input.GetMousePosition()) from the top left of the minimap and multiply it by [MULTIPLYER] to get the position on the map. To calculate [MULTIPLYER], get the distance from the bottom right of the minimap and compare that to the bottom right of the world space map.
- Next, depending on how your game works, I would place a GameObject above the targeted position and ray cast down and receive the position and then set the target location.
I hope this helps, @Azumiar.