Birds Eye View Code?

Can someone teach me or tell me how to create a birds eye view camera position? Is it possible?

--These are simply functions to store the values for the traces calculated in calcview
--Makes it easier to access the tracepos in other files/functions
--To access a player use the following (example
--player:GetPlayerClass():GetData(player, "MPos")
function CLASS:SetData( ply, key, val )
	self.Data[ply] = self.Data[ply] or {}
	self.Data[ply][key] = val
	if CLIENT then
		RunConsoleCommand( "setdata", key, val )

function CLASS:GetData( ply, key )
	if not CLASS.Data[ply] then return nil end
	return CLASS.Data[ply][key] or 0

--This function is needed to adjust the angle for CalcView for widescreen resolutions
local function MPosAimVec(iScreenX,iScreenY,iScreenW,iScreenH,aCamRot,fFoV)
    local fHalfWidth = iScreenW*0.5;
    local fHalfHeight = iScreenH*0.5;
    local d = fHalfWidth/math.tan(fFoV*0.5);

    local vForward=aCamRot:Forward();
    local vRight=aCamRot:Right();
    local vUp=aCamRot:Up();

    return (vForward*d + vRight*(iScreenX-fHalfWidth) + vUp*(fHalfHeight-iScreenY)):Normalize();
local view = { angles = Angle(45,180,0) }
local trace = {}
local angFixTrace = {}
function CLASS:CalcView( ply, pos, angles, fov )
	local x, y, ang, sw, sh, hw, hh, mposx, mposy, ratio
	mposx = gui.MouseX()
	mposy = gui.MouseY()
	sw = ScrW()
	sh = ScrH()
	ratio = sw/sh
	hw = sw / 2
	hh = sh / 2
	x = hw - mposx
	y = hh - mposy
	ang = Angle( 0, math.deg( math.atan2( -y, x ) ) - 90, 0 )
	ang:RotateAroundAxis(ang:Forward(), 45)
    view.fov = fov
	local fovFix = (math.atan(math.tan((fov * math.pi) / 360) * (ratio / (4/3) )) * 360) / math.pi
	trace.start = view.origin
	trace.endpos = trace.start + MPosAimVec(mposx, mposy, sw, sh, view.angles, math.rad(fovFix)) * 5000
	trace.filter = ply
	local tr = util.TraceLine(trace)
	if not tr.Hit then return end
	CLASS:SetData(ply, "MPos", tostring(tr.HitPos)) --The hitpos of the trace on the world
	CLASS:SetData(ply, "MAimVec", tostring(tr.HitPos-ply:EyePos())) --AimVector from the player to the trace

	return view

This is a code I found, and it doesn’t work, since CLASS is a nil value

Please help me! Enjoy your day :slight_smile:

You’re going to have to use

GM:CalcView. Take example #1 and work from there. Throw away the code you found if you have no idea what it does or how it’s supposed to work.