Game Development Community

TGB and t2dShape3D animation problem.

by Adrian Banninga · in Torque Game Builder · 09/21/2011 (2:30 pm) · 2 replies

When I try to play a 3D animation in TGB nothing happens. It seems to get stuck on the first frame.

When just loaded the Idle animation plays but when I use one of the arrow keys to move the player, he moves in the right direction, but only in the first frame of the Move animation, looks as if he is ice skating. Then when I release the key he starts walking in one place.

I did everything in the tutorial but I cannot see error and I have searched the forums for hours already.
Here is the code –


function test3D::OnAdd(%this)
{
datablock TSShapeConstructor(reinstatedsoldierDTS)
{
baseShape = "~/data/shapes/reinstatedsoldier.dts";
sequence0 = "~/data/shapes/reinstatedsoldier-idle.dsq idle";
sequence1 = "~/data/shapes/reinstatedsoldier-move.dsq move";
sequence2 = "~/data/shapes/reinstatedsoldier-attack.dsq attack";
sequence3 = "~/data/shapes/reinstatedsoldier-react.dsq react";
sequence4 = "~/data/shapes/reinstatedsoldier-death.dsq death";
};


%playerModel = new t2dShape3D(playerChar) {
shape = "~/data/shapes/reinstatedsoldier.dts";
intraDetailLevel = "0";
canSaveDynamicFields = "1";
class = "playerClass";
Position = "0.000 0.000";
// shapeRotation = "0 0 3.200";
size = "12.500 12.500";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionCallback = "1";
ConstantForce = "0.000 200.000";
ConstantForceGravitic = "1";
ForceScale = "4";
mountID = "2";
};

%sceneGraph = SceneWindow2D.getSceneGraph();
%sceneGraph.addToScene(%playerModel);

%playerModel.setShapeRotation(0, 270, 0); // if I use playAnimation here it works perfectly!
}


// This s part of my player.cs
function playerClass::setCurrentAnimation(%this)
{
%xVelocity = %this.getLinearVelocityX();
%yVelocity = %this.getLinearVelocityY();

if(%xVelocity > 0)
{
%this.setShapeRotation(0, 270, 0);
}
else if(%xVelocity < 0)
{
%this.setShapeRotation(0, 90, 0);
}

if(%yVelocity !=0)
{
if(%yVelocity < 0)
{
%this.playAnimation(idle); // supposed to be jump but do not have animation
}
else
{
%this.playAnimation(attack); // supposed to be jump but do not have animation
}
}
else
{
%this.airborne = false;

if(%xVelocity != 0)
{
%this.playAnimation(move);
}
// else // when I add this no idle plays, not even at start
// { // without it the last playAnimation plays when char stops
// %this.playAnimation(idle);
// }
}


If I remove the comment from the last else then the player does not even start with the Idle animation and also does nothing when I release the arrow keys to move him.

About the author

Entrepreneur, founder and co-founder of various businesses, with experience gained over 10 years of involvement in the industry with an understanding of client expectations, developer pitfalls and award winning portfolio.


#1
09/22/2011 (4:33 am)
I'm guessing setCurrentAnimation() is called every frame while you hold direction button, then shape would keep restarting animation and only show it's first frame.
#2
09/22/2011 (11:36 am)
Ahh yes that sounds like the problem. Will go tell the guy to just keep on walking. Thanks.