animation/constant force problem
by Hoody · in Torque Game Builder · 04/20/2010 (7:14 am) · 2 replies
Got a small problem with my animation stopping when ever I apply a constant force of more than 10 to stop my characters flying into space when I press jump. Anyone have any ideas what I'm doing wrong? all the animations seem to work fine until I make this change :x
#2
04/20/2010 (7:38 am)
Thnx, what is confusing me though is everything seems to work fine until this change is made, most of the code is just recycled from the samurai tutorial in the tdn section as well :sfunction playerClass::onLevelLoaded(%this, %scenegraph)
{
$pGuy = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
%this.setCollisionMaxIterations(2);
}
function playerLeft()
{
$pGuy.moveLeft = true;
echo("hello");
}
function playerLeftStop()
{
$pGuy.moveLeft = false;
}
function playerRight()
{
$pGuy.moveRight = true;
}
function playerRightStop()
{
$pGuy.moveRight = false;
}
function playerJump()
{
if(!$pGuy.airborne)
{
$pGuy.setLinearVelocityY(-225);
$pGuy.airborne = true;
}
}
function playerClass::updateHorizontal(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX(-60);
}
if(%this.moveRight)
{
%this.setLinearVelocityX(60);
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
if(!%this.airborne)
%this.setLinearVelocityY(0);
}
function playerClass::updateVertical(%this)
{
%yVelocity = %this.getLinearVelocityY();
if(%this.airborne)
{
%this.setLinearVelocityY(0);
%collision = %this.castCollision(0.005);
if(%collision !$= "")
%this.setLinearVelocityX(0);
}
%this.setLinearVelocityY(100);
%collision = %this.castCollision(0.005);
if(%collision $= "")
{
%this.airborne = true;
%this.setConstantForceY(100);
}
else if(%yVelocity < 0 && %this.airborne)
{
%this.setConstantForceY(100);
}
else
{
%this.airborne = false;
%this.setConstantForceY(0);
}
%this.setLinearVelocityY(%yVelocity);
}
function playerClass::updateMovement(%this)
{
%this.updateHorizontal();
%this.updateVertical();
%this.setCurrentAnimation();
}
function playerClass::setCurrentAnimation(%this)
{
%xVelocity = %this.getLinearVelocityX();
%yVelocity = %this.getLinearVelocityY();
if(%xVelocity > 0)
{
%this.setFlip(false, false);
}
else if(%xVelocity < 0)
{
%this.setFlip(true, false);
}
if(%this.airborne)
{
if(%yVelocity < 0)
{
%this.playAnimation(playerJumpUp);
}
else
{
%this.playAnimation(playerJumpDown);
}
}
else
{
if(%xVelocity == 0)
{
%this.playAnimation(playerStand);
}
else
{
if(%this.getAnimationName() $= "playerRun")
{
if(%this.getIsAnimationFinished())
{
%this.playAnimation(playerRun);
}
}
else
{
%this.playAnimation(playerRun);
}
}
}
}
function PlatformerSceneGraph::onUpdateScene()
{
if (isObject($pGuy))
$pGuy.updateMovement();
}
Associate Melv May
The animation system has nothing to do with the physics system so you've got a mistake somewhere in your code, that's all that can be said at this point.