Page 1 of 1

how to get where someone clicked on a map

Posted: 13 Jul 2014, 02:58
by smoth
Image

Code: Select all

function widget:MousePress(mouseX, mouseY, mButton)
	local _, location = Spring.TraceScreenRay(mouseX, mouseY)

	if location ~= nil then
		Spring.Echo(location[1],location[2],location[3])
	end
end
because I could not find the answer searching the forum. Now it is here for someone else to use.

Re: how to get where someone clicked on a map

Posted: 13 Jul 2014, 10:38
by Jools
If mouse is above unit or feature, the "x"-coordinate will instead be the unitID/featureID. Just saying.

Re: how to get where someone clicked on a map

Posted: 13 Jul 2014, 11:07
by gajop
Add a third parameter that specifies you just want map coords instead:
local _, location = Spring.TraceScreenRay(mouseX, mouseY, true)

Re: how to get where someone clicked on a map

Posted: 13 Jul 2014, 16:34
by smoth
Thanks for adding to the thread. I don't normally write this sort of thing so I just handled it all wrong :P

I did this :P

Code: Select all

if location ~= nil and type(location) == "table" then