How do I get the Player or AIPlayer Speed in C++?
by Katrina Rose · in Torque Game Engine · 11/10/2004 (9:20 am) · 1 replies
void Player::pickActionAnimation()
{
// Only select animations in our normal move state.
if (mState != MoveState || mDamageState != Enabled)
return;
if (isMounted())
{
// Go into root position unless something was set explicitly
// from a script.
if (mActionAnimation.action != PlayerData::RootAnim &&
mActionAnimation.action < PlayerData::NumTableActionAnims)
setActionThread(PlayerData::RootAnim,true,false,false);
return;
}
bool forward = true;
U32 action = PlayerData::RootAnim;
if (mFalling)
{
// Not in contact with any surface and falling
action = PlayerData::FallAnim;
}
else
{
if (mContactTimer >= sContactTickTime) {
// Nothing under our feet
action = PlayerData::RootAnim;
}
else
{
// Our feet are on something
// Pick animation that is the best fit for our current velocity.
// Assumes that root is the first animation in the list.
F32 curMax = 0.1;
VectorF vel;
mWorldToObj.mulV(mVelocity,&vel);
for (U32 i = 1; i < PlayerData::NumMoveActionAnims; i++)
{
PlayerData::ActionAnimation &anim = mDataBlock->actionList[i];
if (anim.sequence != -1 && anim.speed) {
F32 d = mDot(vel, anim.dir);
if (d > curMax)
{
curMax = d;
action = i;
forward = true;
}
else
{
// Special case, re-use slide left animation to slide right
if (i == PlayerData::SideLeftAnim && -d > curMax)
{
curMax = -d;
action = i;
forward = false;
}
}
}
}
}
}
//AIPlayer::getMoveSpeed
//Player::getVelocity;
//VectorF vel;
//mWorldToObj.mulV(mVelocity,&vel);
//F32 d = mDot(vel, anim.dir);
//if (d < 0.5 && d > 0.1)
// action = PlayerData::WalkForwardAnim;
setActionThread(action,forward,false,false);
}I need to be able to get the getMoveSpeed of the AIPlayer that is using this animation. I am going to use it to make the AIPlayer walk if there setMoveSpeed is less than 0.5 and run if there speed is above 0.5. I can't figure out how to get the speed of the Player or AIPlayer that is using this pickActionAnimation. Thanks in advance for any help anyone can provide.Marrion
About the author
Torque Owner Erik Madison
For regular players, its similar to (I've got some changes)
F32 speed = getMax(getMaxForwardSpeed() * tempSprintSpeedMult * move->y,
getMaxSideSpeed() * tempSprintSpeedMult * mFabs(move->x));