Game Development Community

dev|Pro Game Development Curriculum

"Adding new positions" enhancements

by Josh Moore · 09/02/2005 (5:25 pm) · 21 comments

This resource builds on the "Adding new positions" resource. So you'll have to have that installed before using this.


GetDamageLocation Fix
The fix for getDamageLocation breaks the percision of the original method. For my purposes, I only needed the general location on the player, since I'm only use it to check for headshots. So this new function will only return head, torso, and legs.

Anyways, replace your Player::getDamageLocation with this:
void Player::getDamageLocation(const Point3F& in_rPos, const char *&out_rpVert, const char *&out_rpQuad)
{
   Point3F newPoint;
   mWorldToObj.mulP(in_rPos, &newPoint);
	F32 zHeight;
	if(mPlayerPosition == 3)
		zHeight = mObjBox.max.y;
	else
	   zHeight = mObjBox.max.z;
   F32 zTorso  = mDataBlock->boxTorsoPercentage;
   F32 zHead   = mDataBlock->boxHeadPercentage;

   zTorso *= zHeight;
   zHead  *= zHeight;

	if(mPlayerPosition == 3) {
		if (newPoint.y <= zTorso)
			out_rpVert = "legs";
		else if (newPoint.y <= zHead)
			out_rpVert = "torso";
		else
			out_rpVert = "head";
	}
	else {
		if (newPoint.z <= zTorso)
			out_rpVert = "legs";
		else if (newPoint.z <= zHead)
			out_rpVert = "torso";
		else
			out_rpVert = "head";
	}

	out_rpQuad = "center"; // default to "center", so we're not returning nothing
}



Keep player on water surface while swimming
For my game, I didn't want to allow players to beable to swim in whatever direction they wanted, so I put together this code to "lock" the players on the water surface while swimming.

Find this line of code
acc.z = (-headRotation.x * (mDataBlock->swimForce / mMass) * 0.25f);
and replace it with this:
// Added code to "lock" the player on the water surface - JM
		  RayInfo rInfo;		

        SimpleQueryList sql;
		  if (isServerObject())
			  gServerSceneGraph->getWaterObjectList(sql);
		  else
			  gClientSceneGraph->getWaterObjectList(sql);
		  F32 wtrSurface = 0;
		  Point3F currentPos = getPosition();
		  for (U32 i = 0; i < sql.mList.size(); i++)
		  {
			  WaterBlock* pBlock = dynamic_cast<WaterBlock*>(sql.mList[ i ]);
			  //if (pBlock && pBlock->isWater( pBlock->getLiquidType() )) {
			  if (pBlock) {
				  if (pBlock->isPointSubmergedSimple(currentPos)) 
					  wtrSurface = pBlock->getSurfaceHeight();
			  }
		  }
		  if(currentPos.z > wtrSurface)
			  wtrSurface = (currentPos.z - wtrSurface)*0.25;
		  else
			  wtrSurface = (wtrSurface - currentPos.z)*0.25;
		  acc.z = wtrSurface;
		  //----


Crouch/Prone Bounding Box Fix
I realized that the current way of changing the boundng box size when going crouch/prone didn't keep the datablock defined bounding box dimensions, because they were hard coded. Just replace your Player::setPlayerPosition method with this(it also includes the onScaleChanged fix):

void Player::setPlayerPosition(S32 position)
{
   F32 len_x, len_y, len_z;
   if (position != mPlayerPosition) {
      if (isProperlyAdded()) {

        // Special case, this one bumps us up to the next position
        if (position == 0) { 
           position = mPlayerPosition + 1;
           if (position > 3)
              position = 1;
        }

         switch (position) {
         case 1: // Stand, walk
          {             
			 len_x = mDataBlock->boxSize.x;
          len_y = mDataBlock->boxSize.y;
          len_z = mDataBlock->boxSize.z;
                         break;
          }
         case 2:  // Crouch, sit
          {
          len_x = mDataBlock->boxSize.x;
          len_y = mDataBlock->boxSize.y;
          len_z = mDataBlock->boxSize.z/2+0.15;// half the player height is too short        
          break;
          }
          case 3:  // Crawl, prone
          {    
          len_x = mDataBlock->boxSize.x;
          len_y = mDataBlock->boxSize.z;
          len_z = mDataBlock->boxSize.z/4;
                         break;
          }
         }
		   mObjBox.max.x = len_x * 0.5;
         mObjBox.max.y = len_y * 0.5;
         mObjBox.max.z = len_z;
         mObjBox.min.x = -mObjBox.max.x;
         mObjBox.min.y = -mObjBox.max.y;
         mObjBox.min.z = 0;
			onScaleChanged();
      }
      mPlayerPosition = position;
   }
     if (isServerObject()) 
      setMaskBits(MoveMask);
}


Potential Bug/Exploit Fix
To fix the pontential bug/exploit I just made the mSwimming variable public and did a simple bool check in the ConsoleMethod, like so:
[i]Player.h:[/i]

public:
   bool mSwimming;
protected:

[i]Player.cc:[/i]

ConsoleMethod( Player, setPlayerPosition, void, 3, 3, "(1=stand, 2=crouch, 3=crawl)")
{
   if(!object->mSwimming)
	   object->setPlayerPosition(dAtof(argv[2]));
}

Also, if you're using this resource you might want to add !mSwimming(and prone check if you don't have it :P) checks to the conform code.
Page«First 1 2 Next»
#21
07/12/2008 (11:35 pm)
Has anyone made a check to see if it is safe to jump or change to a taller position while under something?
Page«First 1 2 Next»