• Getting world vector on mouse position
    0 replies, posted
So I am in need of some assistance with a mechanic of a gamemode I'm working on; I have a top-down view of the player, like this: [IMG]https://i.gyazo.com/17cca0062967cc56bdaf683fb8278a70.png[/IMG] (It can only be rotated via WASD) The above is done using forced 3rd person (simple thirdperson addon / calcview) I wish to be able to get the x,y,z of the world where the mouse clicks, so I can then make the player move to that location (Using nextbots - but that's a different story altogether!) Here is my code so far: [CODE]--[[ CLIENT ]] -- hook.Add( "HUDPaint", "ViewTraces", function( ) local td = { } td.start = gui.ScreenToVector( ScrW()/2, ScrH()/2 ) -- center of screen (I assume this is needed because the calcview rotates the view?) td.endpos = gui.ScreenToVector(gui.MousePos()) tr = util.TraceLine( td ) local st = td.start local en = tr.HitPos surface.SetDrawColor( 255, 255, 255, 255 ) surface.DrawLine( st.x, st.y, en.x, en.y ) end ) concommand.Add("a", function() net.Start("MoveToPos") net.WriteVector(tr.HitPos) net.SendToServer() end) --[[ SERVER ]]-- util.AddNetworkString("MoveToPos") net.Receive("MoveToPos", function(len,ply) ply:SetPos(net.ReadVector()) end)[/CODE] No errors, just the position is always returning HitPos = 0.127707 -0.571862 -0.810348 SOLVED: I was under the implication that EyePos() was the bone position of the eyes, turns out its based on calcview, so I overcomplicated things I guess. Upon reading the following: [url]http://wiki.garrysmod.com/page/Global/EyePos[/url] Example 2 was basically what I needed
Sorry, you need to Log In to post a reply to this thread.