Game Development Community

Changing root animation if the player have melee weapon

by Marcus Araujo · in Torque Game Engine · 07/24/2007 (4:05 pm) · 1 replies

Hi,

I want that my character changes his root animation when he have a melee weapon (like a sword) mounted.
I created a variable named mInCombat, and some functions

Player.cc
--------------------------
void Player::setCombatState(bool inCombat) {
mInCombat = inCombat;
}

ConsoleMethod( Player, setCombatState, void, 3, 3, "(bool inCombat)") {
object->setCombatState(dAtob(argv[2]));
}

In player.h I added PlayerData::RootCombat to the end of the animations enum. I also added the sequence name in the PlayerData::ActionAnimationList in Player.cc and changes NumTableActionAnims to RootCombat + 1.

In the weapon.cs file I added:

weapon.cs
------------------------
function Weapon::onUse(%data,%obj) {
...
%obj.setCombatState(true);
}

I try to change the setActionThread to verify if the player have a weapon mounted and change the root animation:

void Player::setActionThread(U32 action,bool forward,bool hold,bool wait,bool fsp, bool forceSet)
{

....

if (action >= PlayerData::NumActionAnims)
{
Con::errorf("Player::setActionThread(%d): Player action out of range", action);
return;
}

if (mInCombat)
{
if (action == PlayerData::RootAnim) action = PlayerData::RootCombat;
}
...
}

I also try to change Player::pickActionAnimation(): in all places that I have "action = PlayerData::RootAnim;" I added after it "if (mInCombat) action = PlayerData::RootCombat;".

I added Con::errorf() messages to verify if the mInCombat is being changed correctly, and it is ok. But my character keeps the RootAnim animation, instead of play the RootCombat animation.

What can be wrong?

Thank u and sorry for bad english.

#1
07/26/2007 (12:19 am)
I did something similar like this


S32 whichaction = getAttackNow();

if (whichaction == 1)
action = PlayerData::JabAnim;
else if (whichaction == 2)
action = PlayerData::PunchAnim;

etc..


getattacknow() is my own function for getting mAttackNow (which attack I want him to use now).

If you haven't yet, you may need to add mInCombat and any other new mVariables to your pack and unpack functions too.