Posted by: omega
Date posted: May 08 2004 User Rating: 4.5 out of 5.0 | Number of views: 11685 Number of comments: 15 | Description: Simple snippet for a better third person camera with player fading. |
Here's a quick snippet for a functional 3rd person camera replacement. (i've placed it in client-side coding because it's larger than a typical snippet, it's more or less a copy and paste tut :))
It's based on a version of my third person camera from one of my other mods and it also fades out the player when the camera gets close. The only thing this snippet doesn't show you is how to lift up the camera above the players head; however, this isn't hard to add. (Just remember to check for ceilings if you add this feature onto it!!)
I'm just going to toss all of the code right here and add comments explaining different pieces of it. Use it however you wish.
Read the notes about the lines marked with * at the bottom of the article!
| | #define CAM_MIN_DIST 4.0 #define CAM_MAX_DIST 48.0 extern Vector v_angles; void DLLEXPORT CAM_Think( void ) { if( !cam_thirdperson ) return;
float maxDist = cam_idealdist->value; float DistFromWall; pmtrace_t tr; vec3_t origin, camForward;
if (maxDist > CAM_MAX_DIST) maxDist = CAM_MAX_DIST; DistFromWall = maxDist; cam_ofs[ 0 ] = v_angles[0]; cam_ofs[ 1 ] = v_angles[1]; cam_ofs[ 2 ] = v_angles[2];
cl_entity_t *player = gEngfuncs.GetLocalPlayer();
* static int frames = 0; * if (frames < 5) frames++; * if (player && (gEngfuncs.GetMaxClients() > 0) && (gViewPort && gEngfuncs.pEventAPI) && frames >= 5) { origin = player->origin; AngleVectors( cam_ofs, camForward, NULL, NULL ); gEngfuncs.pEventAPI->EV_SetTraceHull(2); gEngfuncs.pEventAPI->EV_SetSolidPlayers(player->index - 1); gEngfuncs.pEventAPI->EV_PlayerTrace( origin, origin - (camForward * (maxDist + 8)), PM_STUDIO_BOX, -1, &tr ); if ( tr.fraction < 1.0 ) { DistFromWall = maxDist * tr.fraction; if( DistFromWall < CAM_MIN_DIST ) DistFromWall = CAM_MIN_DIST; player->curstate.renderamt = 255 * tr.fraction; player->curstate.rendermode = kRenderTransColor; } cam_ofs[ 2 ] = DistFromWall; } }
|
notes: The frame counter and this part of if the statement "&& (gEngfuncs.GetMaxClients() > 0) && (gViewPort && gEngfuncs.pEventAPI) && frames >= 5" are only required if you start the game in third person. ie: +thirdperson on the command line, or you set cam_thirdperson 1 inside IN_Init() (ie: if you want to create a totally third person mod.) Corvidae showed me this ages ago when we were both working on mods that began in third person, he had done the camera before me and figured that out. Without these checks, the mod will crash before you get ingame (player pointer will be valid before everything else) |
|
User Comments
Showing comments 1-15
Many thanks omega, I tried to do something similar to this a while ago and ended up with invisible players...nice snippet! |
|
Where do I put this? Replace the current 3rd person code in in_camera.cpp? |
|
yep, in in_camera.cpp.Edited by Pongles on Jun 04 2004, 16:54:13
|
|
I get invisible players :D |
|
I haven't tested it yet, but you also need to include these ..?
#include "pmtrace.h" #include "event_api.h" #include "pm_defs.h" |
|
could you guys go about telling where i would place this in in_camera.cpp?? im confused on that part |
|
Look for: void DLLEXPORT CAM_Think( void ) { |
|
THnx Omega, one good tut again. But how about that piece of the headheight or head over camera positions? Im a bit confused about that. |
|
Thank you so much. I would also like to know what tawnos is talking about also |
|
Hey Omega.. I get an error about the CamThink function: error C2601: 'CAM_Think' : local function definitions are illegal
How do I fix this? |
|
find where your missing ending brace ( } ) needs to go, before CAM_Think. |
|
ah ok Thanks. edit: argh, I get more errors. Can you explain a bit more of where to place the missing }Edited by Unbreakable on Oct 07 2006, 18:46:16
|
|
my camera is slightly to far to the right of the player and you get a semi side veiw of the character, were in the sdk do i change this (its the z axis i think).
Edit: fixed the problemEdited by cossack13 on Oct 26 2006, 09:09:32
|
|
I have the same problem as cossack13 (wrong camera focus, in the z axis), and I still have not fixed this problem. How do I fix this?Edited by Unknown on Feb 02 2007, 15:33:10
|
|
Take a look at "cam_idealyaw". Initialize it to 0 where appropriate. |
|
You must register to post a comment. If you have already registered, you must login.
|
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (8 guests)
|
|