Game Development Community

Can't move my Fish up.

by Darian Hickman · in Torque Game Builder · 02/19/2007 (6:51 pm) · 0 replies

I copied and pasted the movement code for myfishgamedemo. I can move the fish in every direction except up.
Here's my player.cs file:
function PlayerFish::onLevelLoaded(%this, %scenegraph){
    $FishPlayer = %this;
    moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();");
    moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();");
    moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();");
    moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();");
    moveMap.bindCmd(keyboard, "space", "fishPlayerBoost();", "fishPlayerBoostStop();");
}

function PlayerFish::updateMovement(%this){
    if(%this.moveLeft){
        $FishPlayer.setFlipX(false);
        $FishPlayer.setLinearVelocityX(-$FishPlayer.hSpeed);
    } 
    if(%this.moveRight){
        $FishPlayer.setFlipX(true);
        $FishPlayer.setLinearVelocityX($FishPlayer.hSpeed);
    }
    if(%this.moveUp){
        $FishPlayer.setLinearVelocityY(-$FishPlayer.vSpeed);
    }
    if(%this.moveDown){
        $FishPlayer.setLinearVelocityY($FishPLayer.vSpeed);
    }
    if(!%this.moveLeft && !%this.moveRight){
        %this.setLinearVelocityX(0);
    }
    if(!this.moveUp && !%this.moveDown){
        %this.setLinearVelocityY(0);
    }
}



function fishPlayerDown()
{
   $FishPlayer.moveDown = true;
   $FishPlayer.updateMovement();
}

function fishPlayerUp()
{
   $FishPlayer.moveUp = true;
   $FishPlayer.updateMovement();
}

function fishPlayerLeft()
{
   $FishPlayer.moveLeft = true;
   $FishPlayer.updateMovement();
}


function fishPlayerRight()
{
   $FishPlayer.moveRight = true;
   $FishPlayer.updateMovement();
}


function fishPlayerUpStop()
{
   $FishPlayer.moveUp = false;
   $FishPlayer.updateMovement();
}


function fishPlayerDownStop()
{
   $FishPlayer.moveDown = false;
   $FishPlayer.updateMovement();
}

function fishPlayerLeftStop()
{
   $FishPlayer.moveLeft = false;
   $FishPlayer.updateMovement();
}


function fishPlayerRightStop()
{
   $FishPlayer.moveRight = false;
   $FishPlayer.updateMovement();
}

function fishPlayerBoost(){
    %flipX = $FishPlayer.getFlipX();

    if(%flipX){
        %hSpeed = $FishPlayer.hSpeed * 3;
    }else
    {
        %hSpeed = -$FishPlayer.hSpeed *3;
    }
    $FishPlayer.setLinearVelocityX(%hSpeed);
}

function fishPlayerBoostStop(){
    if($FishPlayer.getFlipX()){
        $FishPlayer.setLinearVelocityX($FishPlayer.hSpeed);
    }else{
        $FishPlayer.setLinearVelocityX(-$FishPlayer.hSpeed);
    }
}