Hello, I've mostly been lurking on Facepunch but now I really need some help.
I'm trying to get a top-down view, and have the player shoot if the cursor is over an elevated surface at that surface.
I have this mostly working, but it also moves the camera around, and I can't seem to get the camera to stay at the same height and distance from the player. Any help is appreciated!
https://files.facepunch.com/forum/upload/172112/b965c0a7-ddfc-4be4-b102-828bc8fe9cb9/ex.png
All is being ran clientside.
function MyCalcView(ply, pos, angles, fov)
local view = {}
view.origin = pos+(angles:Up()*200)
view.angles = Angle(90,0,0)
view.fov = fov
view.drawviewer = true
return view
end
hook.Add("CalcView", "MyCalcView", MyCalcView)
function myCreateMove( cmd, pl, angles )
ang = cmd:GetViewAngles( )
x, y = gui.MousePos( )
v, w = ScrW( ) * .5, ScrH( ) * .5
ang.y = math.deg( math.atan2( v - x, w - y ) )
local campos = LocalPlayer():GetPos( ) + Vector(0,0,200)
local tr = util.TraceLine{ start = campos, endpos = campos + gui.ScreenToVector( gui.MousePos( ) ) * 5000, filter = LocalPlayer(), mask = MASK_SHOT }
local aimposbit = (tr.HitPos - LocalPlayer():EyePos()):Angle()
cmd:SetViewAngles( aimposbit)
end
hook.Add("CreateMove", "myCreateMove", myCreateMove)
local ret = Material("sprites/crosshair_1")
hook.Add("HUDPaint","ReticleDrawing",function()
local tr = LocalPlayer():GetEyeTrace()
local Pos,Normal = tr.HitPos, tr.HitNormal
Pos = Pos + Normal
cam.Start3D(EyePos(),EyeAngles())
render.SetMaterial(ret)
render.DrawQuadEasy(Pos, Normal, 8, 8, Color( 255,255,255,255 ) )
cam.End3D()
end)
local function createpanelbackground()
if !IsValid(Frame) then
local Frame = vgui.Create( "Panel" )
Frame:SetPos( 0, 0 )
Frame:SetSize( ScrW() * 2, ScrH() * 2 )
Frame:SetMouseInputEnabled(true)
Frame:SetCursor( "crosshair" )
gui.EnableScreenClicker( true )
function Frame:OnMousePressed(key)if key == MOUSE_LEFT then
RunConsoleCommand( "+attack" )
elseif key == MOUSE_RIGHT then
RunConsoleCommand( "+attack2" )
end
end
function Frame:OnMouseReleased(key)if key == MOUSE_LEFT then
RunConsoleCommand( "-attack" )
elseif key == MOUSE_RIGHT then
RunConsoleCommand( "-attack2" )
end
end
end
end
hook.Add("Initialize", "createpanelbackground", createpanelbackground)
Sorry, you need to Log In to post a reply to this thread.