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 | More 3rd Person Camera Upgrades
Welcome, Guest! Login | Register

More 3rd Person Camera Upgrades [Print this Article]
Posted by: Yates
Date posted: Mar 23 2005
User Rating: 3 out of 5.0
Number of views: 11865
Number of comments: 7
Description: This is an update to chrono's snippet.
Thank you for your post Chrono, however I found a few problems with it that I figured I would post the fix to.

1) The alpha number is based on tr.fraction which is how close the camera is to the surface. This is incorrect. If the camera is, say 256 units away, and the user moves the mouse so that the camera is up against the wall, then the player would become translucent even though the camera is still far away - it's just up against a wall. Instead, we want to make the player translucent based on how close the camera actually is to the player. You can do that with the following:

Under #define CAM_HULL_OFFSET, add:

 CODE (C++) 

// CAY
#define START_TRANS_DIST    128.0       // how close to player when it starts making model translucent
#define TRANS_DELTA     1.9921875       // Set to 255 / START_TRANS_DIST


 CODE (C++) 

    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


 CODE (C++) 

    if( tr.fraction < 1.0 )
        adjDist = dist * tr.fraction; // move the camera closer if it hit something
        adjDist = dist; // no trace hit, use cam_idealdist without adjusting it

    // CAY - Start making player translucent at given distance
    if ( adjDist < START_TRANS_DIST ) {
        localPlayer->SetRenderMode( kRenderTransColor ); // make him translucent
        localPlayer->SetRenderColorA( (byte)(adjDist * TRANS_DELTA) ); // closer = less opacity

2) You are using MoveToward which seems to be an unfinished utility function that really is just for floats that represent degrees, thus wrapping at 360. Since distance is just a linear floating point, do the following when you want to use a CAM_MAX_DIST greater than 360:


 CODE (C++) 

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


 CODE (C++) 

camAngles[ 2 ] = adjDist;

3) This one is actually just a feature I added, nothing wrong with Chrono's snippet. I set mwheelup to +camin and mweeldown to +camout so that the user can zoom in/out on the fly. I added the following code so that it would automatically enter first person when they zoomed in all the way, and automatically enter third person when they press +camout:

In order for the compiler to know which overloaded ConVar::SetValue() to use, change the following:

 CODE (C++) 

#define CAM_MIN_DIST 16.0


 CODE (C++) 

#define CAM_MIN_DIST 16.0f

Just above:

 CODE (C++) 

    if( !m_fCameraInThirdPerson )


 CODE (C++) 

    // CAY - If they are in first person, and try to zoom out, switch to third person
    if( !m_fCameraInThirdPerson && input->KeyState( &cam_out ) ) {
        cam_idealdist.SetValue( CAM_MIN_DIST );

and right after:

 CODE (C++) 

    if( input->KeyState( &cam_in ) )
        dist -= CAM_DIST_DELTA;
        if( dist < CAM_MIN_DIST )
            // If we go back into first person, reset the angle
            camAngles[ PITCH ] = 0;
            camAngles[ YAW ] = 0;
            dist = CAM_MIN_DIST;


 CODE (C++) 

            // CAY - Auto switch to first person when zooming in all the way

Alternatively, if you want to keep the mousewheel handling weapon menus, you can bind MOUSE3 to +camdistance and then set convars c_maxdistance and c_mindistance to match CAM_MIN_DIST and CAM_MAX_DIST. You'll have to change the code that automatically enters/leaves thirdperson though to use m_fCameraDistanceMove instead of input->KeyState( &cam_in ). This way you hold down mouse3, and then move the mouse up/down to zoom in/out. I'll leave this exercise to someone else.

Hope this helps somebody out there!

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

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

Posted By: MrDev on Apr 01 2005 at 04:52:46
Loving it. do you know how i can increase the ammount by which the camera moves in an out its rather slow...

Posted By: Yates on Apr 03 2005 at 23:15:01
If you are using +camin and +camout then increase CAM_DIST_DELTA, if you are using +camdistance then increase CAM_ANGLE_MOVE.

Posted By: dlswimmer on Apr 18 2005 at 15:54:11
now I know I already asked, but does anyone know how to do a simple add of a new model without having to change the player.mdl? Also, when in third person, to get the model to show, you have to turn the flashlight on then off. Is there a way around this?

Posted By: nisan on May 05 2005 at 17:02:51
When I go into third person, I have a side on view on a slightly see through player. I have compiled a debug version, with developer set to 1, does this make any difference?

Posted By: [ICR] on May 31 2005 at 23:35:38
See the comments in the other post nisan

Posted By: j14rk1n on Jul 31 2005 at 21:46:41
There's a quick fix for the right-side only view... I'm pretty sure it has something to do with idealyaw in in_camera.h on the clientside. I wish I had it, but I can't seem to find it all now..

Posted By: DieparBaby on Apr 20 2006 at 14:24:23
I added this to my HL2MP mod. There are two, probably related, problems that I'm getting. First, the hands from the first person view are visible and second, on some weapons, a long black line originating on the weapon and ending somewhere offscreen shows up. How do I make the hands invisible in the third person view (or either view for that matter)?

Also note that I haven't done the hl2mp content fix yet ( by DieparBaby on Apr 20 2006, 14:25:46

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 (4 guests)
About - Credits - Contact Us

Wavelength version:
Valid XHTML 1.0! Valid CSS!