Player Entity

From Valve Developer Community
Jump to: navigation, search

The Player Entity represents the player character in-game.

Collision Hull

The Player Collision Hull is a simple, convex box; very similar to an NPC Hull.

  • By default, the Player Hull is 32 units wide and 32 units deep, and 72 units high for a Standing/Running/etc Player or 36 units high when Crouching. (By contrast, an NPC Hull#human_hull is
    Confirm:somewhere between 26 and 29 units wide and deep
    ).
  • Note however, any passageway must allow for the 'extra friction unit' required in addition to the Hull dimension (see Dimensions#Player Collision Hull).

Configuration

static CViewVectors g_DefaultViewVectors(
	Vector( 0, 0, 64 ),		//VEC_VIEW 		(m_vView)
								
	Vector(-16, -16, 0 ),		//VEC_HULL_MIN 		(m_vHullMin)
	Vector( 16,  16,  72 ),		//VEC_HULL_MAX 		(m_vHullMax)
													
	Vector(-16, -16, 0 ),		//VEC_DUCK_HULL_MIN 	(m_vDuckHullMin)
	Vector( 16,  16,  36 ),		//VEC_DUCK_HULL_MAX	(m_vDuckHullMax)
	Vector( 0, 0, 28 ),		//VEC_DUCK_VIEW		(m_vDuckView)
													
	Vector(-10, -10, -10 ),		//VEC_OBS_HULL_MIN	(m_vObsHullMin)
	Vector( 10,  10,  10 ),		//VEC_OBS_HULL_MAX	(m_vObsHullMax)
													
	Vector( 0, 0, 14 )		//VEC_DEAD_VIEWHEIGHT 	(m_vDeadViewHeight)
);
where
  • VEC_VIEW is the Standing Player's Viewpoint (e.g. 64 units above origin), and VEC_HULL_MIN and VEC_HULL_MAX are diagonally opposite corners of the Standing Player's Hull.
  • [confirm] that VEC_OBS_HULL_MIN...MAX defines the Spectator mode Hull (20x20x20 units) ?
  • The Player Hull must have a square footprint (like all the NPC Hulls), i.e. it can be as tall as you like, but width & depth must be the same. This is because the hull doesn't rotate with the players direction when detecting collision with the world.
  • The footprint must also be the same for standing and ducking, otherwise (without considerable modifications to code) the player may get stuck in the transition.

The gamemovement.cpp file must also be changed when the collision hull is changed: After the includes (ie. at line 18 is fine) add this code:

#define AIRDUCKORIGINOFFSET (VEC_VIEW - VEC_DUCK_VIEW) //change required in origin to keep view in same place

change line 3943-3945 from:

Vector hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN;
Vector hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN;
Vector viewDelta = ( hullSizeNormal - hullSizeCrouch );

to:

//Vector hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN;
//Vector hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN;
Vector viewDelta = AIRDUCKORIGINOFFSET; //changed: Vector viewDelta = ( hullSizeNormal - hullSizeCrouch );

line 3982-3984, 4033-4035, 4085-4087, 4111-4113 do the same as above

change line 4170 from:

vecEnd.z -= 36.0f;						// This will have to change if bounding hull change!

to:

vecEnd.z -= AIRDUCKORIGINOFFSET.z; //changed: vecEnd.z -= 36.0f;			

and change line 4176 from:

vecEnd.z = mv->GetAbsOrigin().z + ( -36.0f * trace.fraction );

to:

vecEnd.z = mv->GetAbsOrigin().z + ( -AIRDUCKORIGINOFFSET.z * trace.fraction );

You may also want to modify the gamerules.cpp to look like this. The dimensions specified are a normal human size, rather than the 4'6" midget that the defaults specify:

//these are in inches for convenience, NOT map units
#define StandingHeight 72
#define StandingEyeHeight 67
#define CrouchingHeight 45
#define CrouchingEyeHeight 40
#define WidthAndDepth 20

static CViewVectors g_DefaultViewVectors(
	Vector( 0, 0, /*64*/StandingEyeHeight / .75 ),			//VEC_VIEW (m_vView)
								
	Vector(-WidthAndDepth / 1.5, -WidthAndDepth / 1.5, 0 ),		//VEC_HULL_MIN (m_vHullMin)
	Vector( WidthAndDepth / 1.5,  WidthAndDepth / 1.5,  /*72*/StandingHeight / .75 ),		//VEC_HULL_MAX (m_vHullMax)
													
	Vector(-WidthAndDepth / 1.5, -WidthAndDepth / 1.5, 0 ),		//VEC_DUCK_HULL_MIN (m_vDuckHullMin)
	Vector( WidthAndDepth / 1.5,  WidthAndDepth / 1.5,  /*36*/CrouchingHeight / .75 ),		//VEC_DUCK_HULL_MAX	(m_vDuckHullMax)
	Vector( 0, 0, /*28*/CrouchingEyeHeight / .75 ),			//VEC_DUCK_VIEW		(m_vDuckView)
													
	Vector(-10, -10, -10 ),		//VEC_OBS_HULL_MIN	(m_vObsHullMin)
	Vector( 10,  10,  10 ),		//VEC_OBS_HULL_MAX	(m_vObsHullMax)
													
	Vector( 0, 0, 14 )			//VEC_DEAD_VIEWHEIGHT (m_vDeadViewHeight)
);																			

See also

Other entities which affect only the Player Entity: