Talk:Third-person camera

From Valve Developer Community
Jump to: navigation, search

Orange Box

I believe this tutorial should be marked as obsolete in light of the Orange Box update. --~skidz ( Ryan ) 20:38, 21 June 2009 (UTC)

There seems to be a bunch of code added in the orange box sdk that has TF stuff in it. Would it be possible to mimic TF2's third-person animation code to make HL2DM's third-person animation smooth? --Mflux 21:13, 23 Apr 2008 (PDT)

This article seems pretty irrelevant for the Orange Box version of the source engine. You can now enable sv_cheats and type 'thirdperson' and get all of this functionality. Perhaps this should be mentioned somewhere. Kflorence 14:32, 26 Feb 2008 (PST)

The third-person camera view player animations no longer works on the Orange Box version of the engine. I'm working on a fix, but it might take awhile. Nevermind, I'm dumb. Kflorence 13:09, 4 Mar 2008 (PST)

Basic Error Type

Hrm. Followed everything but I get a 'Unknown Command +camchange' Is this still compatible via VS2005? Furthermore,

             == the above code needs to go inside hl2_player.cpp. this then needs to be defined in hl2_player.h so at line 74 put:
              void SetAnimation ( PLAYER_ANIM playerAnim );
              ==

Line 74 is part of a comment. So, what class specifically does it go under?

I'm posting this reply and what seems like a workaround, hoping that it might be useful to those who run into the same problem. Mainly I'm hoping somebody more experienced can chime in with the correct way to do this or confirm that run_mod.bat seems to be broken in latest SDK.
For whatever reason it currently seems that using run_mod.bat doesn't cause your custom client.dll or server.dll to get loaded (I even looked at the modules loaded in the debugger), instead loading the default ones for hl2. However, it seems to load your DLL if you modify run_mod.bat to run hl2.exe from @"C:\Program Files\Steam\steamapps\<username>\source sdk base\hl2.exe" instead of the default HL2 location.
Then, just for testing the camera quickly, change the SteamAppId to 220 and use GCFScape to copy a HL2 map to the mod dir. It goes without saying you can't redistribute the extracted map with your mod.

--Tier0 10:45, 11 Nov 2007 (PST)

SDK Update

After the latest update, the camera will now penetrate the walls and ignore the code to stop it from doing so. --Mflux 01:06, 8 Aug 2006 (PDT)

This is with all the code fixes?—ts2do 01:56, 8 Aug 2006 (PDT)
Indeed it is. You can try it for yourself, 100% reproducable. I will try it again tonight myself just to be sure. --Mflux 14:15, 11 Aug 2006 (PDT)
I've updated the code to fix this --PulledPin

HL2MP ..

Im trying to get the animations working for MP in third person. Any Ideas?

Should work fine. Under in_camera there's a few lines forcing no third person feature in multiplayer. Comment them out.

To find them, search "thirdperson" in that file.


Note that there are a ton of animation problems with MP. From the newest SDK if you follow this tutorial exactly the upper body animations may probably work but it will not be interpolated. I'm hoping someone can figure this out. --Mflux 21:48, 10 Aug 2006 (PDT)


New discovery: if you've implemented the third person camera, and turn on UseClientsideAnimation() in hl2mp_player.cpp constructor, the arms will be perfectly animating but the legs will no longer be animating. I've traced the problem to something resetting the leg animations back to frame zero, though I can't find what's resetting it. Any clues?--Mflux 14:20, 11 Aug 2006 (PDT)


I've been trying to implement the third person camera in MP, but when I start a game and use the +camchange console command, I get several "Bad pstudiohdr in GetSequenceLinearMotion()" errors followed by a crash. This is the first I've done with Source modding, so I'm at a bit of a loss as to what this error means or how to remedy it, and Google's not turning up anything useful.--JKyle 22:19, 14 Aug 2006 (PDT)
That error means your player doesn't have a model. I would recommend getting used to the sdk before diving into this—ts2do 10:04, 15 Aug 2006 (PDT)

Offset issue..

Im trying to make my third person camera an over-the-shoulder type view such as Ghost Recon 2. This third person camera is implemented, where and how do i offset the view?

Try doing cam_idealdist 50 and cam_snapto 1 in console. It should give you a relatively closer camera position than what the default lists in this article. I'm not sure how you would shift it to the left or right, but it shouldn't be too difficult. --Mflux 14:17, 11 Aug 2006 (PDT)

RightView Fix in the CFG file! Important!!

Just found the problem with the camera being placed to the right of the player. It seems that the mentioned fix doesn't work if you have already run your mod before. This is because the 90 degree value for cam_idealyaw gets saved to a config file. The config file can be found in Steam\SteamApps\SourceMods\MY_MOD_DIR\cfg\config.fcg. You can open it up and change

cam_idealpitch "90"

to this

cam_idealpitch "0"

Or if you're realy lazy and don't mind loosing your key-bindings and other configurations, just delete it so it gets regenerated.

--Sunblaze 18:53, 19 Jul 2005 (PDT)

Yah, I forgot to mention that. I added it in. --SubKamran 20:32, 19 Jul 2005 (PDT)

I found that my cam_idealpitch was already set to 0, yet the cam_idealyaw was set to 90, once this was changed to 0, everything was fine. --Neptar 16:44, 21 Feb 2007 (PST)

Player animations

Probably not the right place for this, but I couldn't find any other suitable page.. I've successfully implemented third-person camera, and constructed an entity that can change the player model on the fly. But the player model won't do any animations, it just floats which is really annoying. Does anyone know how to make the player do some animations? --.freelancer 13:23, 29 Nov 2005 (PST)

I can't help you with this, but to help those who can, you might need to say what you've tried and what method you use to change the player model. —Maven (talk) 17:08, 29 Nov 2005 (PST)
Since I'm rather new to the Source engine I haven't tried much to get the animations working, I really don't know how to start. To change the model I get a pointer to the local player (with UTIL_GetLocalPlayer()) and use the SetModel function. Since the model needs to be precached, the model has to already be somewhere in the map. --.freelancer 01:31, 30 Nov 2005 (PST)

the server should control the player's model...—ts2do (Talk | @) 17:49, 30 Nov 2005 (PST)

It's a single-player mod..--.freelancer 07:26, 1 Dec 2005 (PST)

server still control's player model....search for "player.mdl"—ts2do (Talk | @) 17:06, 1 Dec 2005 (PST)

Why should the server care about a purely graphical aspect? —Maven (talk) 17:32, 1 Dec 2005 (PST)

because that's how it does it—ts2do (Talk | @) 17:50, 1 Dec 2005 (PST)

Eh. Perhaps that will teach me not to ask rhetorical questions. —Maven (talk) 17:59, 1 Dec 2005 (PST)
The reason is because the way the game is setup, all animations are driven via server and sent to the client, but the client also does a few things for prediction. This is so even on a single player game, though the effects are negligent.--Mflux 14:22, 11 Aug 2006 (PDT)

@Ts2do: I know how to switch model, that's not the issue. The problem is the new model is only using one animation (if you could even call it that), just like the original player.mdl... --.freelancer 01:54, 2 Dec 2005 (PST)

How bout making a SP mod from the HL2MP SDK, which already controls player animations—ts2do (Talk | @) 05:59, 2 Dec 2005 (PST)

Do I still have all of the SP code available? I know visual stuff like materials and models won't be available..--.freelancer 10:48, 2 Dec 2005 (PST)
It might to better to look at the MP code instead of switching to it, and copy-paste what you need from it. —Maven (talk) 12:53, 2 Dec 2005 (PST)
Yeah, probably. Still don't really know where to look though.. --.freelancer 13:15, 2 Dec 2005 (PST)

Materials and models? You can treat it like it was a SP mod still by utilizing the hl2 base content... how are you doing animations in the player mdl? are you using the male_anim and female_anim or whatever it is...that will only work in MP coz that's what the file is in

Of course if you were to use those animations, you'd need to rename the whole system because NPCs used the anims from the base content—ts2do (Talk | @) 18:21, 2 Dec 2005 (PST)

So basically it would be easier just to create the mod with the MP SDK? Right now I haven't changed anything about the animation system, that's why the player mdl isn't using any animations. That's what I need help with. But using the MP SDK would make that possible more or less without any extra coding? --.freelancer 03:25, 3 Dec 2005 (PST)

Well...Eclipse did it without any MP code I think...try checking out their player mdl

Otherwise...yes MP would work, but you'd have to resolve the issue with NPC animations and PLR animations—ts2do (Talk | @)

Let's see if I got this right. If I use SP SDK my player animations won't work without lots of coding, and if I use MP SDK my NPC animations won't work without lots of coding? Maybe I should just make the mod first-person.. --.freelancer 17:12, 3 Dec 2005 (PST)

With this tutorial, I borrowed the Eclipse player model. The jump animation works, as well as the IDLE animation. In the code there is a place where animations are defined... I didn't mess with it enough to see if I could get the run animation working. But you basically reference the animation in player.mdl. You could also head to the Eclipse forums and send them a PM; PM the programmer "Resforjen." He was the one who got the animations in and working. --SubKamran 07:10, 25 Feb 2006 (PST)

Just a perspective from the inside -- Eclipse (and Samurai Legends) team had issues with getting Animations into game. Specifically with Eclipse, we struggled desperately with the jump animation. What you see in game today was considered so sub-par, it was suggested that we remove jumping from game. I still have Resforjen's contact info, so I can get a hold of him if you need to. --Grash 15:34, 25 Oct 2007 (PDT)

There was a post in VERC about how to add animation in thirdperson view to a single player mod. Will this help? -n-neko 07:54, 25 Feb 2006 (PST)

Free camera

I tried to implement a third person camera that works just like the "free chase cam" known from many mods. "Free" means you can look around with the mouse, but the player model doesn't rotate to where you look at. I dug into all code related to player entities and camera movement. At some point the view angles of the player get synchronized with the angles of the player model, but I couldn't find it. :/ -- Koraktor

Not sure when you posted that but they have this now, it's called thirdperson_mayamode and it's rather difficult to get used to unless your a Maya freak :P --Jenkins08 12:30, 19 April 2009 (UTC)

Random crashes in a clean SDK

Anybody tried the advanced SDK? This will randomly crash for me. Maybe I can get once or twice without it crashing.

Free roaming camera

I'm working on a project which needs a camera that's not bound to any one player. I've just begun to dive into the code and the third-person camera is easy enough to get working, but I'm having trouble figuring out where to go from there. It appears that all the camera's calculations eventually wind up in m_vecCameraOffset, and the elements of m_vecCameraOffset represent the camera's pitch, yaw, and distance from player model respectively. Does that mean Source has no built-in system for a basic two-vector eye/target camera? And if I have to roll my own, where might I start? --Dphrygian 15:09, 1 Sep 2006 (PDT)

Never mind, I found what I was looking for. It's CViewSetup, should anyone else be looking for it. --Dphrygian 15:22, 1 Sep 2006 (PDT)

Anims section: Line 74 should read 174

"The above code needs to go inside hl2_player.cpp. this then needs to be defined in hl2_player.h so at line 74 put: void SetAnimation ( PLAYER_ANIM playerAnim );"

Im -almost certain- about this. I couldnt get it to work with anim and putting that line of code at 74 causes the build not to work. Putting it at line 174 makes more sense and did work for me.

Im not personally confident enough to edit the article seeing as its only the second bit of HL2/C++ coding that Ive done in my life. Anyone fancy taking a look at the code and confirming this? --Poi 09:35, 28 Feb 2007 (PST)

Transparency + DrawWeapon

Are there issues with using both transparency and drawing the weapon when in third person?

It seems like it's a "one or the other" affair. If I switch the commented lines in the c_basecombatweapon.cpp file, then the weapon is drawn in third person, but transparency when the camera gets close to the player no longer works. Is there a fix for this? Can we have both?

RE4 or Ghost Recon Camera Offset

Ive been having trouble finding out how to offset the camera so the effect makes the camera as if it was panned the the right of the player instead of focusing directly toward the origin of the eyes. How would I be able to accomplish the effect of a thirdperson over-the-shoulder camera as seen in Resident Evil 4 or Ghost Recon?

A theory would be to create a function that can be defined through #define xoffset 10 and #define yoffset 2. I don't have much experience in coding so can anyone help me out here? Thanks!

--Bnewsom 16:32, 5 May 2007 (PDT)

Changing Player Model

I'm doing a single-player mod. The tutorial mentions changing the player model to sorta "test" the work. How do you do that? --Charron Same here - can't find anything on changing the player model from the dummy model "models/player.mdl" to something else. --Janoschka Change line 396 (SetModel("models/player.mdl");) to an other model (SetModel("models/alyx.mdl");) but first you need to precache them, i used hl2_client.cpp for precaching --Y@hOO

sv_cheats check

I was trying to implement this in a "from scratch" mod. I struggled with this code for a long time before I found the snippet that disables third person view if sv_cheats isn't enabled. I'm not sure what the best way to bypass that check is so I commented out the following code in in_camera.cpp

// If cheats have been disabled, pull us back out of third-person view. if ( sv_cheats && !sv_cheats->GetBool() ) { CAM_ToFirstPerson(); return; }

Should this be mentioned in the main article? It doesn't appear in the Reference section for in_camera.cpp so I assume this is only a problem with a Scratch mod.

Start the player in Third Person

To default in third person mode edit the in_camera.cpp file find the function

void CInput::Init_Camera( void )
and under the line
m_CameraIsOrthographic = false;
add
m_fCameraInThirdPerson = true;

Should there be a page of "enhancements" to the third person camera? I don't think the "discussion" is the best place for this but I'm not sure where it belongs...

--AndreZero 16 Nov 2007

This only works when launching the game in dev mode loading a map from console with the map <mapname> command, as Thirdperson is considered a cheat.
So the cheat check has to be removed as well. I still have to figure out how to do this, as I'm new to coding ;) --Bluestrike 14:14, 28 July 2009 (UTC)
Found the problem, there is a check that removes thirdperson view, so comment out the following in in_camera.cpp:
// If cheats have been disabled, pull us back out of third-person view.
if ( sv_cheats && !sv_cheats->GetBool() )
{
CAM_ToFirstPerson();
return;
}
--Bluestrike 17:42, 30 July 2009 (UTC)


If you cant see an player animation in 3rd player try checking this link out: Mounting_Other_Content. what i wonder is when you change the angle of the third player view. how do you get an weapon aim that matches the angle ? Unsigned comment added by Fabbecool (talkcontribs) Always sign your posts with four tildes (~~~~)

Muzzle Flash issue.

The muzzle flash doesnt work correctly because it plays the muzzle flash linked to the view model instead of the one linked to the world model. A cheap hack to get around this is to extract the w_smg1.mdl files with gcfscape and put them in your modfolder/models/weapons and rename them to v_smg1.mdl. alternativly use a different model like a prop so that it sets the place for bullets to come from (forgot the word lol) is set to the world model aswell, havnt tried this though. Of course this is only suitable for games which are only third person. I guess a long term solution would be to tell the engine not to render the view model when in third person mode. anyone got any ideas?

See my article in Genre changes for an over-the-shoulder view tutorial which also includes a crosshair change for true aiming in thirdperson.

Crowbar animation

I cant get the crowbar's animation to work. playerAnim isn't PLAYER_ATTACK1 when I use crowbar, and if I manually change idealActivity to ACT_MELEE_ATTACK_SWING it doesnt do anything. I tried to use this act as crouch, it worked, but not in loop, if i do that with act_walk it plays it in loop, please help me with the crowbar :( i really need it in my mod

UPDATE: i used iota() to convert player_anim to char, when im idle, it gives 0, walk 1, jump 2...if i use crowbar and other buggy weapons (like rpg, bugbait, grenade) it doesnt give anything

How does the player.cpp look

How does the player.cpp look because I think I have myne in the wrong place!

hl2_player.cpp and BSCMAKE error

While i was compiling, i got those errors:


error C2509: 'SetAnimation' : member function not declared in 'CHL2_Player' | File: hl2_player.cpp | Line: 3468 | Project: server_hl2

error BK1506 : cannot open file '.\Debug HL2\bitbuf.sbr': No such file or directory | File: BSCMAKE | Project: server_hl2


I'm using Visual Studio 2008 Professional Edition

Anyone who can help me? If you guys dont know how to fix it, can you at least give me the reference codes for "Step 6: Animations"? please :)

Screenshots of this?

Just wondering if someone could upload a screenshot to the article to give an idea of what this looks like? I'd like to try it but I'd prefer to know exactly what it is going to lok like first.--Jimmyjrg 08:50, 14 September 2009 (UTC)