Help - Third Person

Hello,

So I am making a gamemode and the gamemode requires it to be in 3rd person but the view needs to be changed with a key. (like the runescape 3rd person view that can be changed with the arrows keys). If anyone can help with this I would be very thankful! Also I still cannot seem to get the view to actually be in third person when the player spawns in.

I’m working on player view right now for my gamemode, you would need to use the Calc View function to change the player view.

yeah I’ve been trying to use this:


function MyCalcView(ply, pos, angles, fov)
    local view = {}
    view.origin = pos-(angles:Forward()*100)
    view.angles = angles
    view.fov = fov
 
    return view
end
 
hook.Add("CalcView", "MyCalcView", MyCalcView)
 
hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply)
        return true
end)
 

But I just can’t seem to get it working.

Is there a error? or does it just not load?

Just doesn’t load. Am I right putting it in the Cl_init.lua?

I made it into a external file so mine looks like this

core/camera.lua


function MyCalcView(ply, pos, angles, fov)
    local view = {}
    view.origin = pos-(angles:Forward()*100)
    view.angles = angles
    view.fov = fov
 
    return view
end
 
hook.Add("CalcView", "MyCalcView", MyCalcView)
 
hook.Add("ShouldDrawLocalPlayer", "MyHax ShouldDrawLocalPlayer", function(ply)
        return true
end)

then I have it included in both cl_init.lua and init.lua like so

cl_init.lua


include("core/camera.lua")

init.lua


AddCSLuaFile("core/camera.lua")

Okay my third person is now working, is there any way you can get the view to spin around with arrows keys?

I have an idea, gonna test something real quick.

Cheers.

Sorry, I haven’t been able to get it working.

okay, what was your idea though, it might help me to get passed this problem

You don’t need ShouldDrawLocalPlayer if you’re using CalcView.

Modify the view table and add view.drawviewer = true; done…

Here:

[lua]//
// Basic Thirdperson System - Josh ‘Acecool’ Moser
//
hook.Add(“CalcView”, “MyCalcView”, ( _p, _origin, _ang, _fov, _znear, _zfar )
if ( !IsValid( _p ) || !_p.__ThirdPerson ) then return; end

local view = { };
view.origin = _origin - ( _ang:Forward( ) * 100 );
view.angles = _ang;
view.fov = _fov;
view.drawviewer = _p.__ThirdPerson;

return view;

end );

hook.Add(“PlayerBindPress”, “MyHax ShouldDrawLocalPlayer”, function( _p, _bind, _pressed )
if ( _p.__ThirdPerson == nil ) then _p.__ThirdPerson = false; end

local _bInWalk = _p:KeyDown( bit.bor( IN_WALK ) );
if ( _bInWalk ) then
	_p.__ThirdPerson = !_p.__ThirdPerson;
end

end );[/lua]

That is about as simple as it gets. I just set a temp key walk / alt for the toggling of thirdperson through PlayerBindPress. It can use whatever button; but it toggles the Thirdperson value, and calcview takes over.

Ah, for your view to spin around it is a little bit more involved. Use CreateMove to capture your keys, adjust the view based on that. If you want it to rotate in place, it is easy, if you want it to rotate around the player then you need to understand that a circle is 2PI, half circle is PI, and understand circles: https://dl.dropboxusercontent.com/u/26074909/tutoring/poly/simplified_circles_with_poly.lua.html

This may help better since it does the circle components: https://dl.dropboxusercontent.com/u/26074909/tutoring/poly/circles_with_poly.lua.html

If you want to make sure the camera doesn’t go through walls, then that is additional math.