Find cursor click world position

So Kogitsune, Ralle and I have been trying to figure this out for a while now, and we can’t seem to figure a way out that will work well.

I’m currently using CalcView to make a isometric view, and have the aiming and movement working for it, but I can’t figure out how to accurately determine where you click on the ground (world position)

I dont know if its CalcView messing with the functions or what, gui.ScreenToVector (i know its a direction vector, i used it appropriately), ply:GetCursorAimVector(), and a few other functions that I’ve tried are either skewed or wont work for this purpose.

Pretty much the thing im looking for is a point-and-click move KIND of thing (not going to actually move the player, but I need that position)

Did you try using GetEyeTrace and using the hit position? I did it and it does return an accurate position from where your cursor is, but I’m not sure if it will work in CalcView.

GetCursorAimVector() will return GetEyeTrace() if the mouse isnt active, and i’ve tried that too.
That wouldnt work for what I need anyway, because thats a trace from the playermodels eyes, not from the center of the view.

So it’s a top down view some distance above the player? and is the player always dead center of the view?



 x = ScrW( ) / 2 - gui.MouseX( )
 y = ScrH( ) / 2 - gui.MouseY( )
 if CLASS.MouseFollow == false then
  view.origin = pos + Vector(250, 0, 250)
 else
  view.origin = pos + Vector(250 - y / 3,-x / 5,250)
 end
    view.angles = Angle(45,180,0)


Its always 250, 0, 250 away from the player (that’s subject to change) as a base, but if the MouseFollow option is enabled the view follows the mouse a bit (else statement)

Also the angle is at 45 deg

I cant see why using GetCursorAimVector() wont work for this purpose.
Is it because CalcView messes with it?

I had a similar problem a while ago, and after a bit of searching I found this solution by ‘theJ89’:

Tried it myself, and it works perfectly.

I cant get it to work correctly. I know its an aim vector, and im giving it the right args, but it either points to the origin or doesnt point correctly at all.

[editline]3rd November 2010[/editline]



function CLASS:CalcView( ply, pos, angles, fov )
 gui.EnableScreenClicker(true)
 local x, y, ang
 x = ScrW( ) / 2 - gui.MouseX( )
 y = ScrH( ) / 2 - gui.MouseY( )
 ang = Angle( 0, math.deg( math.atan2( -y, x ) ) - 90, 0 )
 ang:RotateAroundAxis(ang:Forward(), 45)
 ply:SetEyeAngles( ang )
 
    local view = {}
 if CLASS.MouseFollow == false then
  view.origin = pos + Vector(250, 0, 250)
 else
  view.origin = pos + Vector(250 - y / 3,-x / 5,250)
 end
    view.angles = Angle(45,180,0)
    view.fov = fov
  
 local trace = {}
  trace.startpos = view.origin
  trace.endpos = trace.startpos + LPCameraScreenToVector(gui.MouseX(), gui.MouseY(), ScrW(), ScrH(), Angle(45,180,0), fov) * 50000
  trace.filter = ply
 local tr = util.TraceLine(trace)
 debugoverlay.Line(ply:EyePos(), tr.HitPos, .005)
    return view
end


So yeah, not working - thar be my code.

You need to convert the fov to radians before you pass it to LPCameraScreenToVector:



function CLASS:CalcView(ply,pos,angles,fov)
	gui.EnableScreenClicker(true)
	local x, y, ang
	x = ScrW( ) / 2 - gui.MouseX( )
	y = ScrH( ) / 2 - gui.MouseY( )
	ang = Angle( 0, math.deg( math.atan2( -y, x ) ) - 90, 0 )
	ang:RotateAroundAxis(ang:Forward(), 45)
	ply:SetEyeAngles( ang )

	local view = {}
	if CLASS.MouseFollow == false then
	view.origin = pos + Vector(250, 0, 250)
	else
	view.origin = pos + Vector(250 - y / 3,-x / 5,250)
	end
	view.angles = Angle(45,180,0)
	view.fov = fov

	local trace = {}
	trace.startpos = view.origin
	trace.endpos = trace.startpos + LPCameraScreenToVector(gui.MouseX(), gui.MouseY(), ScrW(), ScrH(), Angle(45,180,0), 

math.Deg2Rad(fov)


) * 50000
	trace.filter = ply
	local tr = util.TraceLine(trace)
	debugoverlay.Line(ply:EyePos(), tr.HitPos, .005)
	return view
end


Still not working.
I think it might be the way im passing the rotation, but its a static value, so I dont know why it wouldnt work.

OK it turns out I’m just an idiot and didnt realize I had typed trace.startpos and not trace.start.
That fixed it and it works for the most part now but now the trace hits the ground before the mousepos so it’s always a tad bit off.
How would I offset the trace? I know adding a vector too it but nothing static would always work.

That’s odd. I just tried it with your code, and it’s returning the correct position for me:
[IMG_THUMB]http://cubeupload.com/files/7e3507tp03.jpg[/IMG_THUMB]

Will you post your code exactly as you have it?

[editline]4th November 2010[/editline]

Found the error. The code theJ89 wrote doesnt support widescreen resolutions.

Bumping this thread, I noticed that when scaling a viewport (3dcam for example) it sometimes adjust the scale of the rendering (most likely to compensate widescreen resolutions). This seems to be my problem.

Pretty much the same as above.

If someone is really good at math and is willing to help me with this please add me on steam.

thej89 fixed the widescreen issue

it should be updated here:

http://www.facepunch.com/threads/891702