Game Development Community

Hard Coded Player Look and Head Rotation Limits

by Demolishun · in Torque Game Engine · 08/04/2006 (9:52 am) · 5 replies

Why is this stuff hardcoded?:
// look     Used to contol the upper body arm motion.  Must animate
//          vertically +-80 deg.
Player::Range Player::mArmRange(mDegToRad(-80.0f),mDegToRad(+80.0f));

// head     Used to control the direction the head is looking.  Must
//          animated vertically +-80 deg .
Player::Range Player::mHeadVRange(mDegToRad(-80.0f),mDegToRad(+80.0f));

This to me seemed silly so I did this:
void Player::updateLookAnimation()
{
   // Adjust look pos.  This assumes that the animations match
   // the min and max look angles provided in the datablock.
//    if (mArmAnimation.thread) {
//       // TG: Adjust arm position to avoid collision.
//       F32 tp = mControlObject? 0.5:
//          (mHead.x - mArmRange.min) / mArmRange.delta;
//       mShapeInstance->setPos(mArmAnimation.thread,mClampF(tp,0,1));
//    }
//    if (mHeadVThread) {
//       F32 tp = (mHead.x - mHeadVRange.min) / mHeadVRange.delta;
//       mShapeInstance->setPos(mHeadVThread,mClampF(tp,0,1));
//    }
//    if (mHeadHThread) {
//       F32 dt = 2 * mDataBlock->maxLookAngle;
//       F32 tp = (mHead.z + mDataBlock->maxLookAngle) / dt;
//       mShapeInstance->setPos(mHeadHThread,mClampF(tp,0,1));
//    }

   if (mArmAnimation.thread) {
      // TG: Adjust arm position to avoid collision.
      F32 tp = mControlObject? 0.5:
         (mHead.x - mDataBlock->armPMin) / (mDataBlock->armPMax - mDataBlock->armPMin);
      mShapeInstance->setPos(mArmAnimation.thread,mClampF(tp,0,1));
   }
   if (mHeadVThread) {
      F32 tp = (mHead.x - mDataBlock->headPMin) / (mDataBlock->headPMax - mDataBlock->headPMin);
      mShapeInstance->setPos(mHeadVThread,mClampF(tp,0,1));
   }
   if (mHeadHThread) {      
      F32 tp = (mHead.z - mDataBlock->headYMin) / (mDataBlock->headYMax - mDataBlock->headYMin);
      mShapeInstance->setPos(mHeadHThread,mClampF(tp,0,1));
   }
}

Of course you would need to add all the variables and the like to the datablock and have the datablock transfer it over the network, but I think you get the basic idea. Now I can control the limts through the datablock. Of course you would need to modify the animations to fit the angles you choose as well.

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67


#1
08/04/2006 (10:06 am)
Try this in a server/client enviorment, head in with two players. The first player should watch the other, while you move the camera up and down. My bet is you will have interpolation errors on the clients when you move the camera close to the limit range.
#2
08/04/2006 (10:09 am)
Why? I never change the values at run time.
#3
08/04/2006 (10:12 am)
Oh, I also limit the input from the move inside processTick with these same variables.

Doh, I mean in updateMove not processTick
#4
08/04/2006 (12:14 pm)
It was probably just thrown on like that because for a normal humanoid character youl'd never want to be rotating the neck/arm anims more than 80 degrees up or down, not to mention actually letting the camera moving much beyond those would be awkward.
#5
08/05/2006 (1:33 pm)
It is a hard limit. Not a hard upper limit. I tried adjust other parameters and it would mess up really bad.