Map coordinates when clicking with the mouse

Hello,


I'm currently working on a puzzle that requires the player to click on an event with the mouse and then click again somewhere on the map to transfer the event to that specific spot.


So I tried to store the mouse X/Y coordinates in variables, but the problem is: I only know the script call TouchInput.x (and y) and that doesn't give the Map X/Y (in tiles), but apparently the Screen X/Y (in pixels) of the mouse pointer.


Is there some way to store the coordinates of the tile the player clicked on in my variables?


Thanks everyone for reading!
I hope it's okay to post again.


I found a solution myself, with a power I wasn't even aware I could weild: the power of algebra!


1) You can calculate the tile of the screen your event is on when dividing the sceen x/y of that object with the tile width/height.


2) You then have to calculate where the current seen screen starts on the map. That is done with the actual map x/y. Substract the outcome of the 'tile on screen'.


3) Then, after clicking on the destination the event should jump, repeat step 1) but use the mouse screen x/y. Then add the map x/y coordinates from 2). Et voilà!


That's it!
Hi, you can explain in more detail the solution you find?


Thanks in advice. 😎
for people looking around for a way to get the mouse tile coordinates a decade later, for the much MUCH more direct method of doing this, just use the mz/mv script call

$gameMap.canvasToMapX(TouchInput.x);
$gameMap.canvasToMapY(TouchInput.y);

if you don't know how to do scripting, just use two set variable commands and put one of those into the script bar for each of them so you have one for x and y and then set it to update at least once every frame

Original thread: https://forums.rpgmakerweb.com/threads/map-coordinates-when-clicking-with-the-mouse.58211/