Page 1 of 1

Camera angle, water, and you.

Posted: 24 Aug 2010, 23:50
by SpikedHelmet
For simplicity's sake I drew my problem/request.

I'd like it so when I tell a unit to attack water, it attacks the point I tell it to.

EDIT: I realize there's already UI implimentation of an indicator showing where the unit will shoot on the water's surface depending where your mouse is in relation to the actual land underneath, and I SUPPOSE if thats all thats possible then OK -- I'd like the same implimented for moving, fight moving etc -- ALL mouse interaction features with water.

Re: Camera angle, water, and you.

Posted: 25 Aug 2010, 06:28
by Niobium
Sounded like something that could be done in lua, so I went and tried it.

Here's a really simple widget for it, it doesn't account for amphibious units, or not issuing commands off the map, or notifying other widgets of what its doing, etc..

Code: Select all

local function AdjustForWater(px, py, pz)
	
	if py >= 0 then return px, py, pz end
	
	local cx, cy, cz = Spring.GetCameraPosition()
	if cy < 0 then return px, py, pz end
	
	local adj = -py / (py - cy)
	return px + (px - cx) * adj, 0, pz + (pz - cz) * adj
end

function widget:CommandNotify(cmdID, cmdParams, cmdOpts)
	if #cmdParams == 3 and cmdParams[2] < 0 then
		local nx, ny, nz = AdjustForWater(cmdParams[1], cmdParams[2], cmdParams[3])
		Spring.GiveOrder(cmdID, {nx, ny, nz}, cmdOpts)
		return true
	end
end