# CalcView Over the Shoulder View Smoothing Problems

Hey, I’ve been experimenting alot with the CalcView function recently. Particularly trying to make a over the shoulder view, I’ve been trying to get it right but i’m having problems with the crosshair glitching between places. I’ll post a video of this and the code below.

``````
function Camera(ply, origin, angles, fov)
if IsValid(ply) and ply:Alive() then

end
if ply:KeyDown(IN_FORWARD) or ply:KeyDown(IN_BACK) or ply:KeyDown(IN_MOVERIGHT) or ply:KeyDown(IN_MOVELEFT) and ply:IsOnGround() then
local view = {}
view.origin = origin + angles:Forward()*-35 + angles:Up()*2 + angles:Right()*35
view.angles = angles
view.fov = fov

if( ply:GetVelocity():Length() > 150 ) then
view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng ) * .5
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng ) * .2
else
view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng ) * .5
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng ) * .3
end

return view
end

local view = {}
view.origin = origin + angles:Forward()*-35 + angles:Up()*2 + angles:Right()*35
view.angles = angles
view.fov = fov

view.angles.pitch = view.angles.pitch + math.sin( HeadBobAng )
view.angles.yaw = view.angles.yaw + math.cos( HeadBobAng )

return view

end
end

return true
end)

function CameraCrosshair()
local ply = LocalPlayer()
local trace = ply:GetEyeTrace()
local pos = trace.HitPos:ToScreen()
local gap = 5
local length = gap + 5

if !ply:IsBot() and ply:Alive() and IsValid(ply) and gap and length and trace.Hit then
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawLine(pos.x - length, pos.y, pos.x - gap, pos.y)
surface.DrawLine(pos.x + length, pos.y, pos.x + gap, pos.y)
surface.DrawLine(pos.x, pos.y - length, pos.x, pos.y - gap)
surface.DrawLine(pos.x, pos.y + length, pos.x, pos.y + gap)
end
end

``````

The crosshair is not glitching, it’s just marking where it will hit
If you want to make it always be in the same place (It will be really unaccuarate), just replace the trace function by GetAimVector()*distance and then get the screen position there, but as i’ve said, that crosshair will be really useless

But as i’m aiming between the windows, there is no way to shoot through the window. Something has to be wrong here?