Checking for weapon and switching setActionThreads
by Will Sanders · in Torque Game Engine · 07/19/2002 (8:16 pm) · 6 replies
I've got four "forward" animations I'm trying to implement into the game. Walking, running, walking with weapon, running with weapon. Yes, these are full-body animations. The reason why I'm doing it this way is because I can't seem to synch upperbody run/walk animations with the lower body. But anyway...
I've managed to bind a run key and make the player run while playing the running animation. Unfortunately, I think I put the code for calling the actionsequence in the wrong space, because torque (most of the time) keeps restarting the animations before they reach the end of the loop. I call the animations with setActionThread in void Player::pickActionAnimation() of the player.cc file.
------------
if (d > curMax) {
curMax = d;
action = i;
forward = true;
// added for running anim
if(sIsRunning) //static variable I made
{
setActionThread(PlayerData::RunAnim,forward,false,false);
return;
} //end of stuff I added
}
else...
------------
As I said, the animations work, but they keep on getting restarted before running all the way through.
Also, I wanted to add two more animations for running with weapons, but can't figure out how to check in player.cc if the player is holding a weapon. I don't think there's a way... Is there?
I've managed to bind a run key and make the player run while playing the running animation. Unfortunately, I think I put the code for calling the actionsequence in the wrong space, because torque (most of the time) keeps restarting the animations before they reach the end of the loop. I call the animations with setActionThread in void Player::pickActionAnimation() of the player.cc file.
------------
if (d > curMax) {
curMax = d;
action = i;
forward = true;
// added for running anim
if(sIsRunning) //static variable I made
{
setActionThread(PlayerData::RunAnim,forward,false,false);
return;
} //end of stuff I added
}
else...
------------
As I said, the animations work, but they keep on getting restarted before running all the way through.
Also, I wanted to add two more animations for running with weapons, but can't figure out how to check in player.cc if the player is holding a weapon. I don't think there's a way... Is there?
#2
In player.cc:
void hasWeapon(bool hasit)
{
sHasWeapon=hasit;
}
In weapon.cs:
function WeaponImage::onMount(%this, %obj, %slot)
{
%obj.hasWeapon(true);
echo("\nWeapon Mounted!!!");
}
Ofcourse, onMount on weapon.cs is called, but it doesn't call hasWeapon in player.cc because it's not looking in the right place. How can I get my player to reconize if he has a weapon or not? Am I the only person who has asked this?
07/24/2002 (6:08 pm)
So far no luck on trying to get player.cc to reconize if the player has a weapon. This is what I tried:In player.cc:
void hasWeapon(bool hasit)
{
sHasWeapon=hasit;
}
In weapon.cs:
function WeaponImage::onMount(%this, %obj, %slot)
{
%obj.hasWeapon(true);
echo("\nWeapon Mounted!!!");
}
Ofcourse, onMount on weapon.cs is called, but it doesn't call hasWeapon in player.cc because it's not looking in the right place. How can I get my player to reconize if he has a weapon or not? Am I the only person who has asked this?
#3
07/27/2002 (2:26 pm)
/me cries. :'(
#4
GetShapeImage? or some such call.
Phil.
07/27/2002 (3:51 pm)
See if the player has a shapeimage in slot0, thats the weapon hand.GetShapeImage? or some such call.
Phil.
#5
%obj.currentWeapon $= ""
or
%obj.currentWeapon == 0
(or both, not sure if it returns a string or not... :-P)
07/27/2002 (4:15 pm)
%obj.currentWeapon = %obj.getMountedImage($WeaponSlot);then try checking if
%obj.currentWeapon $= ""
or
%obj.currentWeapon == 0
(or both, not sure if it returns a string or not... :-P)
#6
In player.h:
bool sHasWeapon; //(in struct PlayerData)
In player.cc:
// in PlayerData::PlayerData()
sHasWeapon = false;
// in initPersistFields()
addField("sHasWeapon", TypeF32, Offset(sHasWeapon, PlayerData));
// in PlayerData::packData(BitStream* stream)
stream->write(sHasWeapon);
// in PlayerData::unpackData(BitStream* stream)
stream->read(&sHasWeapon);
// This is supposed to set the animation:
// This is at the end of Player::pickActionAnimation()
if(mDataBlock->sHasWeapon)
action = PlayerData::WalkBallAnim;
setActionThread(action,forward,false,false);
//------------
In player.cs:
%obj.currentWeapon = %obj.getMountedImage($WeaponSlot);
if(%obj.currentWeapon != NULL)
{
%obj.sHasWeapon=true;
echo("Weapon Animation Sent!!!");
}
Now, in the game, it DOES echo "Weapon Animation Sent" to the console when it should... However, it doesn't change the animations, NOR does it give me any sort of error.
Any guesses why?
07/28/2002 (7:42 am)
Thanks. Unfortunately, it still doesn't seem to want to work. This is what I've done.In player.h:
bool sHasWeapon; //(in struct PlayerData)
In player.cc:
// in PlayerData::PlayerData()
sHasWeapon = false;
// in initPersistFields()
addField("sHasWeapon", TypeF32, Offset(sHasWeapon, PlayerData));
// in PlayerData::packData(BitStream* stream)
stream->write(sHasWeapon);
// in PlayerData::unpackData(BitStream* stream)
stream->read(&sHasWeapon);
// This is supposed to set the animation:
// This is at the end of Player::pickActionAnimation()
if(mDataBlock->sHasWeapon)
action = PlayerData::WalkBallAnim;
setActionThread(action,forward,false,false);
//------------
In player.cs:
%obj.currentWeapon = %obj.getMountedImage($WeaponSlot);
if(%obj.currentWeapon != NULL)
{
%obj.sHasWeapon=true;
echo("Weapon Animation Sent!!!");
}
Now, in the game, it DOES echo "Weapon Animation Sent" to the console when it should... However, it doesn't change the animations, NOR does it give me any sort of error.
Any guesses why?
Torque Owner Will Sanders
Default Studio Name
But I still don't know how to check to see if the player is carrying a weapon from player.cc... Any ideas?!