Report article RSS Feed Altering the camera angle

The camera angle is an extremely simple thing to alter, and can complete a major step in many specialized mods. Here, you will learn just how to do that, so that anything from a funky FPS to a Grand Theft Auto 2 camera view can be used.

Posted by denreaper on Jun 13th, 2005
Basic Client Side Coding.

[page=Introduction]
So you want to code your super great idea into a game, but you don't have any idea on where to start? Well one perfect place to start is with the camera views. By starting here, you can build a decent version for your modelers and mappers to see what their work will look like in-game. In this tutorial I'm going to use a standard real time strategy view as an example. You will need the standard tools used for coding in the Half-Life engine (MSVS.NET 2003 & the source sdk) and little to no knowledge of the Half-Life 2 engine to do this.

[page=Where do I start?]
You can start off by opening the client project. From there, open in_camera.cpp. This is where everything will be done, which includes some simple numbers that you can alter, and taking out the if statement that disables thirdperson being used in multiplayer mode. Starting at line 30, you will notice many lines that look similar to static ConVar cam_command( "cam_command", "0", FCVAR_CHEAT | FCVAR_ARCHIVE );. These are used to change the camera angle in any way imaginable.

[page=Editing the code]
Before we start digging into those static ConVar's, we are going to disable the if statement that tells the camera not to work in multiplayer mode. Do a search for CAM_ToThirdPerson, and then go a few lines down from there. You should now be around line 438. Find the code that says:

code:
if ( gpGlobals->maxClients > 1 )
{
  //  no thirdperson in multiplayer.
  return;
}
and make it look like this:
/*
if ( gpGlobals->maxClients > 1 )
{
  //  no thirdperson in multiplayer.
  return;
}
*/

 

I would recommend testing to make sure it worked out before you move on.

[page=The camera done your way]
Now that the the camera is working in multiplayer, go back to line 30, and start altering your static ConVars. Experimentation seems to be the best method for this, but if you wanted to make yourself a descent real time strategy view, you would do something like this:

code:
static ConVar cam_command( "cam_command", "0", FCVAR_CHEAT | FCVAR_ARCHIVE );  // tells camera to go to thirdperson
static ConVar cam_snapto( "cam_snapto", "0", FCVAR_ARCHIVE );   // snap to thirdperson view
static ConVar cam_idealyaw( "cam_idealyaw", "90", FCVAR_ARCHIVE );  // thirdperson yaw
static ConVar cam_idealpitch( "cam_idealpitch", "90", FCVAR_ARCHIVE );  // thirdperson pitch
static ConVar cam_idealdist( "cam_idealdist", "300", FCVAR_ARCHIVE );   // thirdperson distance

static ConVar c_maxpitch( "c_maxpitch", "90", FCVAR_ARCHIVE );
static ConVar c_minpitch( "c_minpitch", "0", FCVAR_ARCHIVE );
static ConVar c_maxyaw( "c_maxyaw",   "135", FCVAR_ARCHIVE );
static ConVar c_minyaw( "c_minyaw",   "-135", FCVAR_ARCHIVE );
static ConVar c_maxdistance( "c_maxdistance",   "200", FCVAR_ARCHIVE );
static ConVar c_mindistance( "c_mindistance",   "30", FCVAR_ARCHIVE );
static ConVar c_orthowidth( "c_orthowidth",   "100", FCVAR_ARCHIVE );
static ConVar c_orthoheight( "c_orthoheight",   "100", FCVAR_ARCHIVE );
 

[page=Tying the knots]
Go ahead and compile. After starting up the game, you will have to type in "sv_cheats 1", and "thirdperson" into the console in order to make it work. Stay tuned for a tutorial continuation to solve this shortly. Also, look forward to a Warcraft 3 style zoom in using the scroll wheel. E-mail me at wkunker@gmail.com for help, bugs, comments or suggestions.

Post comment Comments
methy
methy Aug 24 2005, 4:21am says:

A very useful tutorial, I havn't tried it out yet, but it makes sense and will be awsome for my RTS half-lief 2 mod. Is there a way to make it so that you don't have to turn sv_cheats on for this to work. Would I need to put a function in all my levels that does this or can I merely detroy the
"static ConVar cam_command( "cam_command", "0", FCVAR_CHEAT | FCVAR_ARCHIVE ); // tells camera to go to thirdperson" line of code??

Thanks again.

+1 vote     reply to comment
Holymac
Holymac Aug 6 2010, 5:26pm replied:

LOL, delete FCVAR_CHEAT, that marks it as a cheat.

+1 vote     reply to comment
FoxFire
FoxFire Oct 14 2005, 1:01am says:

I'm not to sure, but try this to make it not rely on sv_cheats:
static ConVar cam_command( "cam_command", "0", FCVAR_ARCHIVE );
I'm not sure if that works, try it out.
-FoxFire

+1 vote     reply to comment
Dr.Zoidberg
Dr.Zoidberg Dec 10 2005, 5:56pm says:

what file do i alter? and what dir is it in? does this only work in multiplayer?

+1 vote     reply to comment
Basket_Case
Basket_Case Jan 17 2006, 5:06pm says:

Is there any way that you can do this to change it to 3rd person at specific times? Like when in vehicles?

+1 vote     reply to comment
Da_HL_MaN
Da_HL_MaN Feb 18 2006, 7:30pm says:

Not a GREAT solution, but you could to a temporary solution in the map itself by creating a point_clientcommand and a point_servercommand. Have a logic_auto input two commands, one to the servercommand of "sv_cheats 1" and one to the clientcommand to "thirdperson" (you may want to add another servercommand to disable cheats). While this is in no way a good or especially appropriate solution, it may help beta testing.

-DaMaN

+1 vote     reply to comment
Da_HL_MaN
Da_HL_MaN Feb 18 2006, 7:30pm says:

Oh, and excellent tutorial!

-DaMaN

+1 vote     reply to comment
JDahl
JDahl Aug 26 2006, 6:05am says:

Great, I suppose, tho my model is seen from the right, and walks to the right, with no animation at all. Maybe there's something with versions...

+1 vote     reply to comment
fabiodan
fabiodan Sep 28 2006, 4:31pm says:

this code has a jitter bug in multiplayer mods. any idea on how to fix it?

+1 vote     reply to comment
denreaper
denreaper Oct 4 2006, 9:59pm says:

Try adjusting these:

static ConVar cam_idealyaw( "cam_idealyaw", "90", FCVAR_ARCHIVE ); // thirdperson yaw
static ConVar cam_idealpitch( "cam_idealpitch", "90", FCVAR_ARCHIVE ); // thirdperson pitch

My first guess would be to try adjusting the vales in cam_idealyaw. If that doesn't do it try cam_idealpitch, but it should be cam_idealyaw. Also, make sure you set maxpitch and maxyaw so that the new value can take effect (if necessary).

+1 vote     reply to comment
denreaper
denreaper Oct 4 2006, 10:01pm says:

fabiodan: As for the jitter, It's probably something with the updated physics. I quit HL2 coding when they updated their multiplayer physics. If you do find a solution for this, I'm sure it would help everyone that would potentially wish to utilize this coding.

+1 vote     reply to comment
denreaper
denreaper Oct 4 2006, 10:05pm says:

(Sorry to spam) fabiodan: The jitter sounds like something in the main frame loop updating in an incorrect order. If you have access to that, that's probably what I would investigate first.

Possibly: Camera position is being updated before it checks to see if the controls are pressed each frame iteration, though it seems highly unlikely judging by how organized Valve's coding is. Have you altered the game engine itself at all in your coding?

+1 vote     reply to comment
raphael103
raphael103 Dec 6 2008, 7:42pm says:

hi, im totally new in modding and im also tottaly lost, i have this idea for a mod and it needs to be on thirdperson so i came to this tut...
"You can start off by opening the client project. From there, open in_camera.cpp."
i cant find in_camera.cpp or client project, sorry for the stupid coment but I really am totally lost

+1 vote     reply to comment
raphael103
raphael103 Dec 9 2008, 9:14pm says:

hey, anyone knows how to make thirdperson by default, with no need of sv_cheats 1? please make a tut, i need that

+1 vote     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Tutorial
Browse
Tutorials
Report Abuse
Report article
Related Games
Half-Life 2
Half-Life 2 Single & Multiplayer First Person Shooter