Game Development Community

Animations

by Alan Joyce · in Torque Game Engine · 08/29/2005 (11:22 am) · 3 replies

Does anyone know why the attack animation isn't playing in my code?

CHANGES TO PLAYER.CC
--------------------------------------------------------------------------------------------------------------------------------------------

// Action Animations:
PlayerData::ActionAnimationDef PlayerData::ActionAnimationList[NumTableActionAnims] =
{
// *** WARNING ***
// This array is indexed useing the enum values defined in player.h

// Root is the default animation
{ "root" }, // RootAnim,

// These are selected in the move state based on velocity
{ "run", { 0,+1,0 } }, // RunForwardAnim,
{ "back", { 0,-1,0 } }, // BackBackwardAnim
{ "left", {-1,0,0} }, // SideLeftAnim,
{ "right", {+1,0,0} }, // SideRightAnim,

// These are set explicitly based on player actions
{ "fall" }, // FallAnim
{ "jump" }, // JumpAnim
{ "standjump" }, // StandJumpAnim
{ "land" }, // LandAnim
{ "attack" }, // AttackAnim
};

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;
//}
}
}


CHANGES TO PLAYER.H
--------------------------------------------------------------------------------------------------------------------------------------------

enum {
// *** WARNING ***
// These enum values are used to index the ActionAnimationList
// array instantiated in player.cc
// The first five are selected in the move state based on velocity
RootAnim,
RunForwardAnim,
BackBackwardAnim,
SideLeftAnim,
SideRightAnim,

// These are set explicitly based on player actions
FallAnim,
JumpAnim,
StandJumpAnim,
LandAnim,
AttackAnim,

//
NumMoveActionAnims = SideRightAnim + 1,
NumTableActionAnims = AttackAnim + 1,
NumExtraActionAnims = 58,
NumActionAnims = NumTableActionAnims + NumExtraActionAnims,
ActionAnimBits = 10,
NullAnimation = (1 << ActionAnimBits) - 1
};

#1
08/29/2005 (11:22 am)
CALLS IN AIPLAYER.CS
--------------------------------------------------------------------------------------------------------------------------------------------

//exec("~/data/shapes/monkey/monkey.cs");
exec("~/data/shapes/tatoo/tatoo.cs");
//exec("~/data/shapes/halfpint/halfpint.cs");
//exec("~/data/shapes/kinghak/hak.cs");
//exec("~/data/shapes/spike/spike.cs");
//exec("~/data/shapes/croc/croc.cs");

// Generic
//-----------------------------------------------------------------------------

// Monkey
//-----------------------------------------------------------------------------
datablock PlayerData(Monkey : PlayerBody)
{
className = DefaultAIPlayer;

// shapeFile = "~/data/shapes/monkey/monkey.dts";
shapeFile = "~/data/shapes/tatoo/tatoo.dts";
// shapeFile = "~/data/shapes/halfpint/halfpint.dts";
// shapeFile = "~/data/shapes/kinghak/hak.dts";
// shapeFile = "~/data/shapes/spike/spike.dts";
// shapeFile = "~/data/shapes/croc/croc.dts";

maxForwardSpeed = 7;

sightRange = 80;
sightAngleParmeter = 0.6;
hearingDistance = 30;
hearingQuality = 0.5;

huntingDuration = 30000; // in ms
stopDuration = 5000; // in ms
restDuration = 5000; // in ms
};

//*****************************************************************************
// AI Players think functions implemented in datablocks
//*****************************************************************************

// Default AI Player
//-----------------------------------------------------------------------------
function DefaultAIPlayer::think(%datablock, %player)
{
if(!%player.stop)
{
if(%player.patrol)
{
if(%player.search())
{
%player.startHunting();

error("test");
error("playing");

echo("player1 : " @ %player);
%player.attack();

}
}
if(%player.hunt)
{
%datablock.hunting(%player);
}
}
}

function AIPlayer::attack(%this)
{
echo("player3 : " @ %this);
echo("Playing attack");
%this.setActionThread("attack");
echo("Played attack");
}


MAX FILE
--------------------------------------------------------------------------------------------------------------------------------------------

tatoo_attack.dsq



TATOO.CS
--------------------------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

datablock TSShapeConstructor(tatooDts)
{
baseShape = "./tatoo.dts";
sequence0 = "./tatoo_root.dsq root";
sequence1 = "./tatoo_forward.dsq run";
sequence5 = "./tatoo_attack.dsq attack";
};
#2
08/29/2005 (11:49 am)
Have you tried including sequences 2-4 in your TSShapeConstructor?
#3
08/29/2005 (11:52 am)
You don't need to, even if i change the attack sequence number to 2 it still won't work.