Click on minimap move camera/view to it

(- Click for resources) #1

Hello,

@kengiAsked me if i could add an option to my minimap to also get an RTS minimap. The option would be: click on the plane(minimap) and move the camera to that spot.

My question: Is this possible, to grab/convert a clicked position on a plane and convert it into real world coordinates?

Kengi is not the only one who wanted this, there are more people including myself, but i have absolutely no idea if that is even possible.

#edit
Now that i think of it (still no clue if it is possible, just my thoughts)

camera in ortho mode, creating a square minimap (the official map is always square) . So then we scale the minimap down, then when clicked on it grab the position/normal/etc. and converting that up in combination with the scaling to get the (world)location on the normal map(the big version).

1 Like

(kengi) #2

BGMC21 | CaveX16, look that code he have put an minimap working, but i dont know how is work.

0 Likes

(kengi) #3

other link ive find, id ont know if it can help

0 Likes

(Lyeb) #4

I would second Cotaks’ edit.

You need the minimap to be an exact, scaled down representation of the dimensions of the actual map. Make map and minimap origin the exact center of the scene, i.e. have it sit at [0, 0].

To move the minimap, make it an overlay and use camera shift.
To move the main game camera, use mouse over and multiply hit position by scale factor.
These would correspond to world coordinates on the map.

But there might be a more elegant solution. I’ll see if I can think up something.

0 Likes

(sdfgeoff) #5

The basic process is:

Screen space -> Minimap space -> camera space -> world space

You can get the mouse position in screen space. From that you need to figure out where on the minimap they clicked, where that is relative to the camera, and then where the camera is relative to the world.

If you’re using a RTT, then the UV-coordinates of the plane displaying the minimap are equivalent to the camera space. So you can use a raycast and extract the hitUV.

If you’re not using RTT (for example in CaveX16 as linked above which uses viewports), then you have to find another way to map the click into minimap space. I can’t remember what I did in CaveX16, but I probably put a plane where the minimap was and used the UV’s anyway (BTW: viewports are way more performant than RTT, but there are some limitations with them).

Going from camera space to world space is easy if you have an orthographic camera. Multiply by the width, offset by the minimap-camera’s position, and add them together. If you have a perspective camera, you may wish to convert the camera space into a vec3 and multiply by the inverse camera projection matrix. Then you could raycast from the camera until it hit something. There is a function for mapping from camera space to a world direction vector in the BGE API, but it only works on perspective cameras, so it isn’t a general purpose solution.

You can see the code from CaveX16 here:

It looks like I hardcoded the fact that the camera was pointing world-down so I could just assume world_space = click_uv * world_size - which is definitely the easiest solution. (Line 167)

0 Likes

(- Click for resources) #6

I tried a few things yesterday, and indeed grabbing the uv worked, and just multiply by the dimension and creating an if statement to find out where on the minimap was clicked. This works for a full view of the map, but when zoomed in a bit, so only a part of the map is displayed it wont work.

i guess i just need to add an additional option, to select rts map and then the minimap zooms out to show the whole map instead of a part of it.

i looked at your cave game yesterday, and i could not figure out how you did it lol, so i tried my way.
//edit ah ok i see now you use a full sized map as well. i just going to add an other option with the minimp(fullsize) then it works

0 Likes