• Calcview Broken ??
    11 replies, posted
Hello, Thanks for viewing this topic. Here my calcview, this code make my screen full black, where is the error because console doesn't return an error .. function GM:CalcView( ply, pos, angles, fov ) local view = {} local MouseX, MouseY = gui.MousePos() local dist = 350 --Make the origin of the mouse the center of the screen local NormX = ( 0.5 - MouseX / ScrW() ) / 0.5 local NormY = ( 0.5 - MouseY / ScrH() ) / 0.5 local Center = ply:GetPos() + Vector( NormY * dist * 0.4, NormX * dist * 0.4, 75 ) self.LastViewPosition = LerpVector(  math.pow( math.max( Center:Distance( self.LastViewPosition ), 300) / 300, 2 )   * FrameTime() * ( ply:GetVelocity():Length() / 50 + 1.5 ), self.LastViewPosition,  Center  ) view.origin = self.LastViewPosition - angles:Forward() * dist view.angles = Angle( angles.p, angles.y, angles.r ) return view end
This version works for me: hook.Add( "CalcView", "blah", function( ply, pos, angles, fov ) ply.LastViewPosition = ply.LastViewPosition or pos local view = {} local MouseX, MouseY = gui.MousePos() local dist = 350 --Make the origin of the mouse the center of the screen local NormX = ( 0.5 - MouseX / ScrW() ) / 0.5 local NormY = ( 0.5 - MouseY / ScrH() ) / 0.5 local center = ply:GetPos() + Vector( NormY * dist * 0.4, NormX * dist * 0.4, 75 ) ply.LastViewPosition = LerpVector( math.pow( math.max( center:Distance( ply.LastViewPosition ), 300) / 300, 2 )  * FrameTime() * ( ply:GetVelocity():Length() / 50 + 1.5 ), ply.LastViewPosition, center ) view.origin = ply.LastViewPosition - angles:Forward() * dist view.angles = Angle( angles.p, angles.y, angles.r ) return view end ) I changed 3 things: The first is that I made it a hook because it's usually not a good idea to override such an important function The second is that I changed 'self.LastViewPosition' to be 'ply.LastViewPosition' because self wasn't defined otherwise The third is I set 'ply.LastViewPosition' to 'pos' at the start, because it wasn't defined otherwise.
Yes, it' works but how can i make a view from the top, without the need to create a prop and setviewentity on it ? just with calview for example Thanks you, you are a life saver <3
What do you mean 'from the top'? Do you mean top down? Do you mean third person?
top down
The calculations you're doing in CalcView are probably behaving strangely
origin return : angles = 64.995 0.000 0.000 origin = -nan(ind) -nan(ind) -nan(ind) angles = 64.995 0.000 0.000 origin = -nan(ind) -nan(ind) -nan(ind) angles = 64.995 0.000 0.000
if the origin is -nan(ind) then there must be a problem somewhere in the code. I don't really know what it's doing and I'm not good with lerp so I don't know the problem exactly
i think is because of : gui.MousePos() returning nan ?
that'd make sense. I think there's a way to avoid using the mouse position. I've never seen it used in CalcView before. Can't you use pos or angles or something provided to you already by CalcView instead?
i have made this and it work always ! local MouseX = 0 local MouseY = 0 if gui.MousePos() then local MouseX, MouseY = gui.MousePos() else local MouseX = 0 local MouseY = 0 end -- you have a better solution like getaimvector or mouseonsceen if it exist ^^
Here's a better and more conservative idea... local MouseX = 0 local MouseY = 0 if gui.MousePos() then MouseX, MouseY = gui.MousePos() end -- You don't have to write local, because it's already cached. -- You don't have to make an else statement, because it's 0 by default.
Sorry, you need to Log In to post a reply to this thread.