Game Development Community

having trouble getting ninja to walk

by Kevin Dresher · in Torque Game Builder · 01/18/2012 (11:21 am) · 0 replies

Im working on the miniplatform tutorial. I typed out the script, the character jumps just fine but the character will not move left or right.


code/

function playerClass::onLevelLoaded(%this, %scenegraph)
{
%force = 20;
sceneWindow2D.mount($pGuy, "0 0", %force, true);

$pGuy = %this;

moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();","");

}

function playerLeft()
{
$pGuy.moveLeft = true;
}

function playerLeftStop()
{
$pGuy.moveLeft = false;

}

function playerRight()
{
$pGuy.moveRight = false;
}

function playerClass::updateMovement(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX(-60);
}

if(%this.moveRight)
{
%this.setLinearVelocityX(60);
}

if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX(0);
}
}

function playerJump()
{
$pGuy.setLinearVelocityY(-225);

}

function PlatformerSceneGraph::onUpdateScene()
{
$pGuy.updateMovement();
}