CG_OffsetThirdPersonView Question


(bobblehat) #1

This is a question of questions I suppose, but anyway:

When in third person view, and after a minor edit to the crosshair code, the player model gets in the way of the player aim so that you cannot see what you are shooting at.

I was thinking of having the player model off to one side, but no matter what I seem to edit in CG_OffsetThirdPersonView (line 239, cg_view.c), I end up with something undesired like view getting closer to the model as the view turns, or the character not aiming/walking towards the crosshair.

What I’d really like to have, is have the view “fixed to a relative point” from the player (and turning the player model with the view attached) rather than the view centered on the player. I guess its like the default view in Gears of War (Screenshot).

Does anyone have any ideas about how I might achieve that?

I have already tried changing some of the vectors, but that led me to the problems that I just mentioned. Any help is greatly appreciated :).


(Elite) #2

Look realllllyyy closely here:

/*
===============
CG_PlayerAngles

Handles seperate torso motion

  legs pivot based on direction of movement

  head always looks exactly at cent->lerpAngles

  if motion < 20 degrees, show in head only
  if < 45 degrees, also show in torso
===============
*/
static void CG_PlayerAngles( centity_t *cent, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) {

(bobblehat) #3

I see what use it has but I’m still unsure about getting the player to be to the side. Anyway, thanks for the help - Its the second time you’ve helped me now :slight_smile:


(Elite) #4

Ahh… I thought you wanted to simply adjust the angles he was facing or if you couldn’t do that then put hiom to the side.

Perhaps, I don’t knwo if theis is an option, but just try it if you can, but since all the tags are named allready, and et allready checks the name of the tags when it adds the parts… can you just add an offset to the tag_torso when it is placed into the world?? Everything else I think attahces to that, so it should still all line up. Haven’t tested this or anything, but this is the same concept I would use to line up my new weapon models instead of rebuilding the entire md3 for positioning.

If that won’t work, this is where you want to look at:

/*
===============
CG_Player
===============
*/
void CG_Player( centity_t *cent )

Of particular interest in this function would be somewhere around here, I briefly tested it out and it worked fine, just make sure to add an offset with the VectorCopy function:

//
	// add the body
	//
	if( cent->currentState.eType == ET_CORPSE && cent->currentState.time2 == 1 ) {
		body.hModel		= character->undressedCorpseModel;
		body.customSkin	= character->undressedCorpseSkin;
	} else {
		body.customSkin	= character->skin;
		body.hModel		= character->mesh;
	}

	VectorCopy( playerOrigin, body.origin );
	VectorCopy( lightorigin, body.lightingOrigin );
	body.shadowPlane = shadowPlane;
	body.renderfx = renderfx;
	VectorCopy( body.origin, body.oldorigin );	// don't positionally lerp at all

	cent->pe.bodyRefEnt = body;

Also, in the same function, there is a section of code just above the last block of code I listed, closer to the start of the function, for mounted weapons positioning, you will want to look at that as well:

if( cent->currentState.eFlags & EF_MOUNTEDTANK ) {
		VectorCopy( cg_entities[ cg_entities[ cent->currentState.clientNum ].tagParent ].mountedMG42Player.origin, playerOrigin );
	} else if( cent->currentState.eFlags & EF_MG42_ACTIVE || cent->currentState.eFlags & EF_AAGUN_ACTIVE ) { 	// Arnout: see if we're attached to a gun
		centity_t *mg42;
		int num;

		// find the mg42 we're attached to
		for ( num = 0 ; num < cg.snap->numEntities ; num++ ) {
			mg42 = &cg_entities[ cg.snap->entities[ num ].number ];
			if( mg42->currentState.eType == ET_MG42_BARREL &&
				mg42->currentState.otherEntityNum == cent->currentState.number ) {
				// found it, clamp behind gun
				vec3_t	forward, right, up;

				//AngleVectors (mg42->s.apos.trBase, forward, right, up);
				AngleVectors ( cent->lerpAngles, forward, right, up );
				VectorMA ( mg42->currentState.pos.trBase, -36, forward, playerOrigin );
				playerOrigin[2] = cent->lerpOrigin[2];
				break;
			}
		}

		if( num == cg.snap->numEntities ) {
			VectorCopy( cent->lerpOrigin, playerOrigin );
		}
	} else {
		VectorCopy( cent->lerpOrigin, playerOrigin );
	}

(bobblehat) #5

I did try changing player/body.origin in that example code you posted, which looked great at first, but as you turn the player the view gets closer and further away.

I guess I wasn’t too clear about what exactly I was trying to do, but instead of my initial idea I have opted for a different view that stays behind and above the players head. This seems to avoid any issues with the view moving about as the view still centers on the player.

I did hit a problem with the third person view in general however. It seems that the game decides where the player is aiming, depending on the “FOCUS_DISTANCE” (as its defined in the code). From what I understand, it’s the “depth” to the crosshair. (In game I noticed this, because when a target is close, bullets hit below your crosshair and from far away they go above it - so to me focus distance is the sweet spot where bullets hit the right height). It’s really noticeable with the panzerfaust more than anything.

Can anyone confirm that?


(bobblehat) #6

Oh forget it, it turns out that because I have changed the view point the cross hair gets messed up too.

In the normal view, the cross hair is at the player’s head height which is where the view points from and the bullets shoot from.

I however, have raised the view above the player and so the bullets are still aiming forward, but below the cross hair by however many units I moved the view up by.


(Elite) #7

You’re so close, don’t give up now… just add an offset to the bullet origin by the same amount of units (in g_weapon).