Post tutorial Report RSS 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 on - 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:

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:

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 - - 1,221 comments

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.

Reply Good karma Bad karma+1 vote
Holymac
Holymac - - 255 comments

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

Reply Good karma Bad karma+1 vote
FoxFire
FoxFire - - 24 comments

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

Reply Good karma Bad karma+1 vote
Dr.Zoidberg
Dr.Zoidberg - - 45 comments

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

Reply Good karma Bad karma+1 vote
Basket_Case
Basket_Case - - 58 comments

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

Reply Good karma Bad karma+1 vote
Da_HL_MaN
Da_HL_MaN - - 8 comments

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

Reply Good karma Bad karma+1 vote
Da_HL_MaN
Da_HL_MaN - - 8 comments

Oh, and excellent tutorial!

-DaMaN

Reply Good karma Bad karma+1 vote
JDahl
JDahl - - 1 comments

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...

Reply Good karma Bad karma+1 vote
fabiodan
fabiodan - - 90 comments

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

Reply Good karma Bad karma+1 vote
denreaper Author
denreaper - - 52 comments

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).

Reply Good karma+1 vote
denreaper Author
denreaper - - 52 comments

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.

Reply Good karma+1 vote
denreaper Author
denreaper - - 52 comments

(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?

Reply Good karma+1 vote
raphael103
raphael103 - - 31 comments

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

Reply Good karma Bad karma+1 vote
raphael103
raphael103 - - 31 comments

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

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: