View Full Version : 3rd Person Tutorial
shuy3n
07-24-2007, 07:53 AM
Does anyone know of a working third person tutorial or code snippets as i tried the valve one and it didn't quite work was basically the same as sv_cheats 1 , thirdperson.
hope you can help :)
btw i need it for sp not mp :$
Keair
07-24-2007, 01:07 PM
I did the third person tutorial, and, aside from the fact that you need to remove the part about it only working if sv_cheats is set to 1, it seemed to work fine. What about it isn't changeable or exactly to your liking?
shuy3n
07-25-2007, 07:36 AM
tbh its more than likely my crappy coding skills but the end piece tells me to place
void SetAnimation ( PLAYER_ANIM playerAnim ); on line 174 of hl2_player.h
but this is being occupied by another piece of code and if i put it on line 174 anyway and move the code thats there to 178 it doesn't compile.
also the weapons dont appear in the players hand in 3rd person mode and it sticks transparent i.e if i back up to a wall it goes transparent but then stays like it, and my player doesn't auto appear i have to use the flash light to get him to appear. also when i said it was like sv_cheats 1 thirdperson i found out i had to delete my cfg file to reset the angle my apologies for that :)
sorry your probably looking at this and thinking its easy to fix but i know jack about coding and I'm having to depend on tutorials and snippets.
tbh i think most of this is because of the new sdk?
Keair
07-25-2007, 08:22 PM
I wouldn't know. I only recently began coding source myself. I didn't get very far into third person view, as I was just doing it to familiarize myself with the code. I didn't get weapons in the player's hands either, unfortunately. However, I know that there are other's who have done third person view, so perhaps one of them can help you.
And, it might not be directly applicable, but you should try to find code that deals with NPCs and how they're shown. If you utilize that, you might have better luck. I saw might because I honestly don't know. But that's where I'd start.
I would disregard all the tutorials and start with this
in C_BasePlayer.cpp change this
bool C_BasePlayer::ShouldDrawLocalPlayer()
{
return true;
//return input->CAM_IsThirdPerson() || ( ToolsEnabled() && ToolFramework_IsThirdPersonCamera() );
}
this will draw the player model then add the below to the HL2_Player just like in the valve tutorial. As for the camera position just adjust your distance yaw pitch variables and add some ai to control it as you play (there is no tutorial for that.) I'm pretty sure if you do it this way the weapons should just go into the players hand. Also you won't have to use cheats or turn on a flashlight or anything stupid like that. I think all that I did was not put it into thirdperson if that makes sense. I made a surveillance camera out of a modified point_viewcontrol so I completely skipped having to adjust view angles and distance. Actually you could probably just add an unmodified point_viewcontrol with the appropriate flags and have that follow your player; again no ai.
line 180 HL2_Player.H
void SetAnimation ( PLAYER_ANIM playerAnim );
End of HL2_Player.cpp
void CHL2_Player::SetAnimation( PLAYER_ANIM playerAnim )
{
int animDesired;
float speed;
speed = GetAbsVelocity().Length2D();
if ( GetFlags() & ( FL_FROZEN | FL_ATCONTROLS ) )
{
speed = 0;
playerAnim = PLAYER_IDLE;
}
Activity idealActivity = ACT_RUN;
// This could stand to be redone. Why is playerAnim abstracted from activity? (sjb)
if ( playerAnim == PLAYER_JUMP)
{
idealActivity = ACT_JUMP;
}
else if ( playerAnim == PLAYER_JUMP)
{
idealActivity = ACT_HOP;
}
else if ( playerAnim == PLAYER_DIE )
{
if ( m_lifeState == LIFE_ALIVE )
{
return;
}
}
else if ( playerAnim == PLAYER_ATTACK1 )
{
if ( GetActivity( ) == ACT_HOVER ||
GetActivity( ) == ACT_SWIM ||
GetActivity( ) == ACT_HOP ||
GetActivity( ) == ACT_LEAP ||
GetActivity( ) == ACT_DIESIMPLE )
{
idealActivity = GetActivity( );
}
else
{
idealActivity = ACT_GESTURE_RANGE_ATTACK1;
}
}
else if ( playerAnim == PLAYER_RELOAD )
{
idealActivity = ACT_GESTURE_RELOAD;
}
else if ( playerAnim == PLAYER_IDLE || playerAnim == PLAYER_WALK )
{
if ( !( GetFlags() & FL_ONGROUND ) && GetActivity( ) == ACT_HL2MP_JUMP ) // Still jumping
{
idealActivity = GetActivity( );
}
/*
else if ( GetWaterLevel() > 1 )
{
if ( speed == 0 )
idealActivity = ACT_HOVER;
else
idealActivity = ACT_SWIM;
}
*/
else
{
if ( GetFlags() & FL_DUCKING )
{
if ( speed > 0 )
{
idealActivity = ACT_WALK_CROUCH;
}
else
{
idealActivity = ACT_COVER_LOW; //ACT_IDLE_CROUCH;
}
}
else
{
if ( speed > 0 )
{
idealActivity = m_fIsSprinting ? ACT_WALK : ACT_RUN;
}
else
{
idealActivity = ACT_IDLE;
}
}
}
//idealActivity = TranslateTeamActivity( idealActivity );
}
if ( idealActivity == ACT_GESTURE_RANGE_ATTACK1 )
{
RestartGesture( Weapon_TranslateActivity( idealActivity ) );
// FIXME: this seems a bit wacked
Weapon_SetActivity( Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 );
return;
}
else if ( idealActivity == ACT_GESTURE_RELOAD )
{
RestartGesture( Weapon_TranslateActivity( idealActivity ) );
return;
}
else
{
SetActivity( idealActivity );
animDesired = SelectWeightedSequence( Weapon_TranslateActivity ( idealActivity ) );
if (animDesired == -1)
{
animDesired = SelectWeightedSequence( idealActivity );
if ( animDesired == -1 )
{
animDesired = 0;
}
}
// Already using the desired animation?
if ( GetSequence() == animDesired )
return;
m_flPlaybackRate = 1.0;
ResetSequence( animDesired );
SetCycle( 0 );
return;
}
// Already using the desired animation?
if ( GetSequence() == animDesired )
return;
//Msg( "Set animation to %d\n", animDesired );
// Reset to first frame of desired animation
ResetSequence( animDesired );
SetCycle( 0 );
}
shuy3n
07-27-2007, 10:44 AM
.\hl2_dll\hl2_player.cpp(3615) : error C2084: function 'void CHL2_Player::SetAnimation(PLAYER_ANIM)' already has a body
c:\mymod\src\dlls\hl2_dll\hl2_player.h(180) : see previous definition of 'SetAnimation'
any ideas what that means ?
but before i added the second part of what you said i.e just the code to draw the player it seemed to be fine :)
-----
ignore me it was because i forgot to delete the code from the valve tutorial lol
Did you add it twice?????? You would have put it in if you followed the valve tutorial!
shuy3n
07-27-2007, 03:30 PM
yer i did :P see told you i was a coding noobie. im going to do a fresh create a mod and retry what you said above as i think the valve tut is conflicting with yours, which seems to be working great :)
shuy3n
08-14-2007, 04:09 AM
what are the settings for point_viewcontrol to get this to work as i just cant seem to get it.
You would have to add a point_viewcontrol and set hold infinite and snap to angles and then in the setup make !player your target and parent. Then just place the camera at the spawn point of your player (obvious flaw.) So to have the camera spawn at the same point as the player does you could spawn a camera in code on map spawn, not easy! You could check off start at player position and then adjust the start at player position to slightly behind the player also not easy. What problems are you having with the in_camera code what can't you get working????????
shuy3n
08-19-2007, 04:35 PM
to be honest the point_viewcontrol isn't working i tried all of your suggestions about !player before but no joy. although i can see the players head from my view port as if i was inside the head looking out how or where would i adjust that angle position?
nankasento
03-12-2008, 10:26 AM
Hi, I've been trying for days now to get a third person camera to work in a SP MOD and have tried several tutorials.
The best result so far I got with the information beky posted above.
I got the point_viewcontrol to work, it's fixed at the position I placed it in hammer but it looks at the player.
The reason I did this not in code but in hammer is, that I wasn't able to enable the point_viewcontrol, while I could trigger the enable in hammer by the use of a triggerbox.
The code I created for this is:
//
//setup 3ds person point_viewcontrol
//
//CBaseEntity *pViewControl = CreateEntityByName( "point_viewcontrol");
// CBaseEntity *pViewControl = gEntList.FindEntityByName( NULL, "3rdPersonCamera" );
//pViewControl->KeyValue( "Parent", this->GetClassname() );
//pViewControl->AddSpawnFlags( 10 );
//pViewControl->Activate();
//pViewControl->SetSpan
//
// setup 3rd person point_viewcontrol
//
And I placed this in HL2_player.cpp
So the above code doesn't work because you can't enable it but if I can get that to work, this should work as well instead of having to need to place a point_viewcontrol entity in hammer in every level you'd create.
So my question for this piece of code is; Does someone know how you could enable the point_viewcontrol from code instead of using a triggerbox with an output, onStartTouch, Enable on the point_viewcontrol entity in hammer?
This would be very handy.
Another problem I have is that it doesn't draw the model but it does set it, because I can move around and the camera follows something when I move around and jump.
I looked at the following thread on the forum: "Player Model will only display as basic player.mdl model" (http://forums.steampowered.com/forums/showthread.php?t=662451&highlight=player+model) I tried what they are talking about but that doesn't work for me.
Can anyone tell me why the model isn't drawn when I use the code that beky posted? Even though the entity is there.
I have used CFGscape to get the player model files and copied it the appropriate folder of my own MOD, so that shouldn't be the case.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.