So I use TraceScreenRay and Pos2BuildPos to translate the current mouse cursor position to the build position.
But when you move the mouse over a feature the return value of TraceScreenRay returns the height of the feature (I think). The returned y-value is higher than before. According to my understanding the second parameter "onlyCoords" indicates that features should not be taken into account? At least when it is true all return values have the type "ground".
Here are two screenshots that show the issue. Since the ghosted factory is identical the widget is supposed to draw the arrow at the same position in both images which is not the case.


In the console there are the debug outputs shown. I think it has something to do with the feature that gets hit by the screen ray. The y-value of the TraceScreenRay is different then also.
In the end the z-Value of the BuildPos is different which should not be the case.
Last but not least, thats the source code in question:
Code: Select all
Spring.Echo("Mouse: X: " .. mx .. " Y: " .. my)
local type, coords = spTraceScreenRay(mx, my, true, true)
if not coords then return end
local centerX = coords[1]
local centerY = coords[2]
local centerZ = coords[3]
Spring.Echo("Trace: Type: " .. type .. " X: " .. centerX .. " Y: " .. centerY .. " Z: " .. centerZ)
centerX, centerY, centerZ = spPos2BuildPos( unitDefID, centerX, centerY, centerZ )
Spring.Echo("BuilPos: X: " .. centerX .. " Y: " .. centerY .. " Z: " .. centerZ)