Animations wont play
by Gary "Cartoonist" Cooper · in Torque Game Builder · 02/21/2010 (10:48 pm) · 7 replies
I have written the code for my character movement by looking at code done by other people and my character moves the way i want him to move but the animations wont play, it's like the code for the animation is cancelled out. it only has 1 animation to run and a waiting animation. Can anybody tell me what is wrong with the code? if you have any questions on how the player moves please ask.
not sure how to put a code file so sorry if it is too long.
not sure how to put a code file so sorry if it is too long.
if (!isObject(BunnyMovementBehavior))
{
%template = new BehaviorTemplate(BunnyMovementBehavior);
%template.friendlyName = "Bunny Controls";
%template.behaviorType = "Input";
%template.description = "Bunny Movement Controls";
%template.addBehaviorField(upKey, "Key to bind to upward movement", keybind, "keyboard up");
%template.addBehaviorField(downKey, "Key to bind to downward movement", keybind, "keyboard
down");
%template.addBehaviorField(leftKey, "Key to bind to left movement", keybind, "keyboard left");
%template.addBehaviorField(rightKey, "Key to bind to right movement", keybind, "keyboard
right");
%template.addBehaviorField(verticalSpeed, "Speed when moving vertically", float, 20.0);
%template.addBehaviorField(horizontalSpeed, "Speed when moving horizontally", float, 20.0);
}
function BunnyMovementBehavior::onBehaviorAdd(%this)
{
if (!isObject(moveMap))
return;
moveMap.bindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), "moveUp", %this);
moveMap.bindObj(getWord(%this.downKey, 0), getWord(%this.downKey, 1), "moveDown", %this);
moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "moveLeft", %this);
moveMap.bindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), "moveRight", %this);
%this.up = 0;
%this.down = 0;
%this.left = 0;
%this.right = 0;
}
function BunnyMovementBehavior::onBehaviorRemove(%this)
{
if (!isObject(moveMap))
return;
%this.owner.disableUpdateCallback();
moveMap.unbindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), %this);
moveMap.unbindObj(getWord(%this.downKey, 0), getWord(%this.downKey, 1), %this);
moveMap.unbindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), %this);
moveMap.unbindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), %this);
%this.up = 0;
%this.down = 0;
%this.left = 0;
%this.right = 0;
}
function BunnyMovementBehavior::updateMovement(%this)
{
%this.owner.setLinearVelocityX((%this.right - %this.left) * %this.horizontalSpeed);
%this.owner.setLinearVelocityY((%this.down - %this.up) * %this.verticalSpeed);
}
function BunnyMovementBehavior::moveUp(%this, %val)
{
%this.up = %val;
%this.updateMovement();
}
function BunnyMovementBehavior::moveDown(%this, %val)
{
%this.down = %val;
%this.updateMovement();
}
function BunnyMovementBehavior::moveLeft(%this, %val)
{
%this.left = %val;
%this.updateMovement();
}
function BunnyMovementBehavior::moveRight(%this, %val)
{
%this.right = %val;
%this.updateMovement();
}
function BunnyMovementBehavior::Animation(%this)
{
%xVelocity = %this.owner.getLinearVelocityX();
%yVelocity = %this.owner.getLinearVelocityY();
if(%xVelocity > 0)
{
%this.owner.setFlip(false, false);
}
else if(%xVelocity < 0)
{
%this.owner.setFlip(true, false);
}
if(%this.owner.airborne)
{
if(%yVelocity != 0)
{
if(%this.owner.getAnimationName() $= "bunnywait")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(bunnywait);
}}
else
{
%this.owner.playAnimation(bunnywait);
}}}
else
{
if(%xVelocity == 0)
{
%this.owner.playAnimation(bunnywait);
}
else
{
if(%this.owner.getAnimationName() $= "bunnywalk")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(bunnywalk);
}}
else
{
%this.owner.playAnimation(bunnywalk);
}}}}About the author
#2
i thought that this was the function, its at the end of the behavior.
02/21/2010 (11:26 pm)
How exactly would i call the animation function?i thought that this was the function, its at the end of the behavior.
function BunnyMovementBehavior::Animation(%this)
{
%xVelocity = %this.owner.getLinearVelocityX();
%yVelocity = %this.owner.getLinearVelocityY();
if(%xVelocity > 0)
{
%this.owner.setFlip(false, false);
}
else if(%xVelocity < 0)
{
%this.owner.setFlip(true, false);
}
if(%this.owner.airborne)
{
if(%yVelocity != 0)
{
if(%this.owner.getAnimationName() $= "bunnywait")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(bunnywait);
}}
else
{
%this.owner.playAnimation(bunnywait);
}}}
else
{
if(%xVelocity == 0)
{
%this.owner.playAnimation(bunnywait);
}
else
{
if(%this.owner.getAnimationName() $= "bunnywalk")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(bunnywalk);
}}
else
{
%this.owner.playAnimation(bunnywalk);
}}}}
#3
02/22/2010 (2:07 am)
function BunnyMovementBehavior::Animation(%this)
{
%xVelocity = %this.owner.getLinearVelocityX();
%yVelocity = %this.owner.getLinearVelocityY();
if(%xVelocity > 0)
{
%this.owner.setFlip(false, false);
}
else if(%xVelocity < 0)
{
%this.owner.setFlip(true, false);
}
if(%this.owner.airborne)
{
if(%yVelocity != 0)
{
if(%this.owner.getAnimationName() $= "bunnywait")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(bunnywait);
}}
else
{
%this.owner.playAnimation(bunnywait);
}}}
else
{
if(%xVelocity == 0)
{
%this.owner.playAnimation(bunnywait);
}
else
{
if(%this.owner.getAnimationName() $= "bunnywalk")
{
if(%this.owner.getIsAnimationFinished())
{
%this.owner.playAnimation(bunnywalk);
}}
else
{
%this.owner.playAnimation(bunnywalk);
}}}}
#4
02/22/2010 (2:59 am)
You could try calling it at the end of your "updateMovement" function.
#6
If so, I'd start putting echo statements in the Animation function to make sure that the flow is correct.
02/22/2010 (8:45 pm)
Just to make sure, did you do this?function BunnyMovementBehavior::updateMovement(%this)
{
%this.owner.setLinearVelocityX((%this.right - %this.left) * %this.horizontalSpeed);
%this.owner.setLinearVelocityY((%this.down - %this.up) * %this.verticalSpeed);
%this.Animation();
}If so, I'd start putting echo statements in the Animation function to make sure that the flow is correct.
#7
02/23/2010 (4:23 pm)
Thank you for all your help, it works :D
Associate William Lee Sims
Machine Code Games
You should check the "MarkupLite is enabled" link to see how to format your code to look like code, too. It makes it easier to look through the code.