Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/sites/a/ on line 20
Wavelength | Your Game Editing Resource | Third Person Camera Upgrades
Welcome, Guest! Login | Register

Third Person Camera Upgrades [Print this Article]
Posted by: Crono
Date posted: Dec 08 2004
User Rating: 1 out of 5.0
Number of views: 14744
Number of comments: 9
Description: Collision check, translucency
I believe this to be an accurate-ish remix of Omega's improved third person camera for Half-Life 1, located here.

I will hope this is correct but assume it is not, and any suggestions or corrections are more than welcome. Being that this is a snippet, I will endeavor to keep it terse.

Line numbers are reliant on following modifications in order.
All of this takes place in cl_dll\in_camera.cpp.

@Line 20
 CODE (C++) 
#define CAM_MIN_DIST 30.0

Remove this line.

@Line 27
 CODE (C++) 
#define CAM_MIN_DIST 16.0 // Don't let the camera get any closer than ...
#define CAM_MAX_DIST 96.0 // ... or any farther away than ...
#define CAM_HULL_OFFSET 6.0 // the size of the bounding hull used for collision checking



@Lines 395 - 412
 CODE (C++) 
        if( camAngles[ YAW ] - viewangles[ YAW ] != cam_idealyaw.GetFloat() )
            camAngles[ YAW ] = MoveToward( camAngles[ YAW ], cam_idealyaw.GetFloat() + viewangles[ YAW ], CAM_ANGLE_SPEED );
        if( camAngles[ PITCH ] - viewangles[ PITCH ] != cam_idealpitch.GetFloat() )
            camAngles[ PITCH ] = MoveToward( camAngles[ PITCH ], cam_idealpitch.GetFloat() + viewangles[ PITCH ], CAM_ANGLE_SPEED );
        if( !C_BasePlayer::GetLocalPlayer() ) {
            // this code can be hit from the main menu, where it will crash
            camAngles[ 2 ] = dist; // if there's no localplayer to calc from
        else {
            trace_t tr;
            float adjDist = dist;
            C_BasePlayer* localPlayer = C_BasePlayer::GetLocalPlayer();

            Vector origin = localPlayer->GetLocalOrigin(); // find our player's origin
            origin += localPlayer->GetViewOffset(); // and from there, his eye position

            AngleVectors( QAngle(camAngles.x, camAngles.y, camAngles.z),
                         &camForward, NULL, NULL ); // get the forward vector

            UTIL_TraceHull( origin, origin - (camForward * dist),
                            CAM_HULL_MIN, CAM_HULL_MAX,
                            MASK_SOLID, NULL, &tr ); // use our previously #defined hull to collision trace

            if( tr.fraction < 1.0 ) {
                adjDist = dist * tr.fraction; // move the camera closer if it hit something
                localPlayer->SetRenderMode( kRenderTransColor ); // make him translucent
                localPlayer->SetRenderColorA( (byte)(255 * tr.fraction) ); // closer = less opacity
            else {
                adjDist = dist; // no trace hit, use cam_idealdist without adjusting it

            if( adjDist < CAM_MIN_DIST )
                adjDist = CAM_MIN_DIST; // clamp up to minimum

            if( adjDist > CAM_MAX_DIST )
                adjDist = CAM_MAX_DIST; // clamp down to maximum

            camAngles[ 2 ] = MoveToward( camAngles[ 2 ], adjDist, CAM_ANGLE_SPEED );

    m_vecCameraOffset[ 0 ] = camAngles[ 0 ];
    m_vecCameraOffset[ 1 ] = camAngles[ 1 ];
    m_vecCameraOffset[ 2 ] = camAngles[ 2 ];


Rate This Article
This article is currently rated: 1 out of 5.0 (1 Votes)

You have to register to rate this article.
User Comments Showing comments 1-9

Posted By: fred on Dec 09 2004 at 14:33:06
Is this SP or MP? I'm having troubles getting the guy to show at all in SP code, its either the floating hand model or nothing (I still havn't found the playerdraw stuff).

Posted By: Crono on Dec 09 2004 at 21:31:00
Sorry, this was done entirely with the barebones MP SDK setup, I was sure I'd mentioned that somewhere.

If I open single player Half-Life 2 right now, then set sv_cheats 1, then type "thirdperson" in console, I have no player model. If I turn the flashlight on and back off, I go from no player model to a flat colored ugly player model with no animation.

I don't think it's your fault or my code's.Edited by Crono on Dec 09 2004, 21:36:45

Posted By: jim_the_coder on Dec 12 2004 at 20:50:15
This has been covered in the forums. I believe the problem is that Valve didn't intend thirdperson to be used in SP, and as such they never bothered doing the player model. Apparently looking at the model shows that it's only got 3 anims. If you make your own player model it should work fine :) I'll tell you when I've got it working...


I can confirm that this tutorial does what it's supposed to just fine :) You still need your own player model though.Edited by jim_the_coder on Dec 19 2004, 15:28:50

Posted By: ChildeRoland on Feb 02 2005 at 21:05:25
Has anybody had any luck getting this to work while in the vehicles? I got it working while running around (even placed it over the players head). But, when I get in the Jeep the camera goes back to looking to the left of where the player/vehicle is actually looking.

Any ideas what I ccan do about this?

Posted By: paccer on Feb 07 2005 at 16:41:21
(at about line 471)

// Do allow third person in TF2 for now
#if !defined( TF2_CLIENT_DLL ) && !defined( CSTRIKE_DLL )

#if !defined( _DEBUG )
    if ( gpGlobals->maxClients > 1 )
        // no thirdperson in multiplayer.


This is preventing thirdperson in multiplayerEdited by paccer on Feb 10 2005, 17:07:09

Posted By: woodyos on Feb 08 2005 at 20:36:35
Yes it does. If you comment out the return, it'll work though.
I'm experiencing a different problem now though; I see my character from the side. So if I press the "walk forward" key, the model will walk to the right of my screen, which is his front. Does anyone know how to fix this?

Posted By: paccer on Feb 10 2005 at 15:02:54
find idealyaw (in_camera.cpp), its defined somewhere in the top as far as i remember - set it to 0 instead of 90, and delete your config.cfg or make sure c_ commands are same as defined in in_camera.cpp..
Alternatively, you can just set c_idealyaw to 0, but it will default to 90 then.

My translucency still doesnt work tho - does it work for anyone else?

Sorry.. my translucency actually works fine :)Edited by paccer on Feb 10 2005, 17:06:19

Posted By: Vash on Feb 19 2005 at 16:20:53
This is a fantastic tutorial and was just what I needed - thank you. And thank you to paccer, whos comments helped me fix the yaw value.Edited by Vash on Feb 19 2005, 16:21:55

Posted By: dlswimmer on Apr 16 2005 at 17:33:19
how do you switch the model ? is there an easy way to do it while using a model like alyx that is already in the game? Thanks for the help.

You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 05 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005

Latest Comments
knock knock
General | News
By: MIFUNE | Dec 31 2017
knock knock
General | News
By: omega | Dec 22 2016
knock knock
General | News
By: MIFUNE | Oct 10 2015
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
knock knock
General | News
By: Whistler | Nov 05 2011
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (9 guests)
About - Credits - Contact Us

Wavelength version:
Valid XHTML 1.0! Valid CSS!