I was trying to make a camera for a gamemode, but the mouse position is not aligned with where it should be in the map. Does anyone know how to solve this? Thanks.
here is the code
[CODE] -----------------------VARS AND INIT STUUFF
local X = 0
local Y = 0
local Z = 0
local ZOOM = 100
-----------------------VARS AND INIT STUUFF
--------------------------------------CAMERA DAHORA DO AGE
function CalcView2( ply, origin, angles, fov )
local tracedata = {}
tracedata.start = Vector(X,Y,(8*ZOOM)+100)
tracedata.endpos = Vector(X,Y,(8*ZOOM)+100) - Vector(0,0,10000)
tracedata.mask = NPCWORLDSTATIC
Camera_trace = util.TraceLine(tracedata)
view = {}
gui.EnableScreenClicker(true)
local x_mouse, y_mouse = gui.MousePos()
//zoom
if (input.IsKeyDown( 50 ) and ZOOM > 0) then
ZOOM = ZOOM - 1
elseif(input.IsKeyDown( 49 ) and ZOOM < 100) then
ZOOM = ZOOM + 1
end
//zoom
local borda = 4
sens_convar = CreateClientConVar("agemod_sensbility", "2", true, false)
local sensibilidade = ((ZOOM/100)*sens_convar:GetInt()/2) + (sens_convar:GetInt()/2)
//mouse pos
if (x_mouse < borda) then X = X - sensibilidade end
if (x_mouse > (ScrW()-borda)) then X = X + sensibilidade end
if (y_mouse < borda) then Y = Y + sensibilidade end
if (y_mouse > (ScrH()-borda)) then Y = Y - sensibilidade end
//mouse pos
Z = ((8*ZOOM)+100 + Camera_trace.HitPos.z)
view.origin = Vector(X,Y,Z)
view.angles = Angle((0.3*ZOOM)+30,90,0)
--view.angles = Angle(90,90,0)
view.fov = fov*0.8
return GAMEMODE:CalcView(ply,view.origin,view.angles,view.fov)
end
hook.Add("CalcView", "CalcView2", CalcView2)
--------------------------------------CAMERA DAHORA DO AGE
-----------------------------CODIGO DE DETECÇAO DO MOUSE VECTOR
function mouse_glow()
w_mousetrace = util.QuickTrace( Vector(X,Y,Z), (gui.ScreenToVector( gui.MousePos() )*10000) )
cam.Start3D(view.origin,view.angles)
render.SetMaterial( Material("sprites/blueglow2") ) --"luz maneira
render.DrawQuadEasy( w_mousetrace.HitPos, --position of the rect
w_mousetrace.HitNormal, --direction to face in
128, 128, --size of the rect
Color( 255,255,255,255 ) --color
)
cam.End3D()
end
hook.Add( "HUDPaint", "mouse_glow", mouse_glow )
-----------------------------CODIGO DE DETECÇAO DO MOUSE VECTOR [/CODE]and the video
[URL]http://www.youtube.com/watch?v=-mBPIBCy0M4[/URL]
sorry for my english... i'm brazilian =P
EDIT: Sorry, I forgot a part of the code
What are X, Y and Z?
Sorry, you need to Log In to post a reply to this thread.