How to drag the current viewing window inside a minimap?

Hi

I have created a minimap at top right corner of the screen. Also, there’s a small rectangle window inside it that focuses on the current screen that the main camera is seeing. It also responds to WASD well. Now, I want to be able to click anywhere within the minimap that should make the current viewing window smoothly slide over to the clicked location. Also, dragging the window must make the camera move to the corresponding location.

FYI, the main camera sees the screen and the minimap has a textured background that’s rendered by a different camera that sees the entire environment.

Can anyone give me ideas on how to approach this? I have tried many different ways but none seems to work. I am open to any suggestions from you guys.

Thanks a lot!

Are you are rendering the minimap camera to the onscreen rectangle using its normalised viewport rect (as opposed to using a render texture)? If so, you can use Camera.ScreenToWorldPoint on the minimap camera to convert the mouse position to a world coordinate:-

var groundPos = minimapCam.ScreenToWorldPoint(Input.mousePosition);

Having got that point, you can move the main view camera so it is positioned overhead.