Game Development Community

Simple Jump Function issues

by Matt James · in Torque Game Builder · 11/16/2012 (11:16 am) · 2 replies

Please note: i'm a complete newbie, so take everything with a grain of salt.

Summary: Game is in the style of Castle Crashers / Streets of Rage where you can move around in the X/Y field freely.

Problem: When I "jump" it moves the player diagonally by a small portion towards the center of the scenegraph. If you end up being in the 'center' it stops moving diagonally.

I'm simply wanting it to move a set amount directly UP in the Y axis (or negative rather), and then return back to your starting X/Y position.

new ActionMap(moveMap);
   moveMap.bind(keyboard, "space", jump);   
   moveMap.push();


function playerClass::onLevelLoaded(%this)
{
   $player = %this;
   // $player.updateMovement();
}


function jump()
{
     $playerPosY = $player.getPositionY();
     $playerPosX = $player.getPositionX();
     
     $player.moveTo("$playerPosX $playerPosY-50", 150, true, true, true, 0.1);
     
}

function playerClass::onPositionTarget(%this)
{
      %this.moveTo("$playerPosX $playerPosY", 150, true, true, true, 0.1);
}

Thanks for any assistance, sorry for the n00bness !

#1
11/16/2012 (11:52 am)
It appears at first glance your moveTo is incorrect. Try this:
function jump()
{
     $playerPosY = $player.getPositionY();
     $playerPosX = $player.getPositionX();
     
     $player.moveTo($playerPosX SPC $playerPosY-50, 150, true, true, true, 0.1);
}

Also.. it may not work with the math as you have it, so you may need to change it to something like:

function jump()
{
     $playerPosY = $player.getPositionY();
     $playerPosX = $player.getPositionX();
     $playerPosJump = $playerPosY - 50;
     $player.moveTo($playerPosX SPC $playerPosJump, 150, true, true, true, 0.1);
}

Note the change I made: SPC and.. the quotes because otherwise.. you're sending it something you shouldn't ;)

Move to: moveTo(t2dVector positionTarget, float linearSpeed,[bool autoStop=true],[bool callback=false],[bool snap=true],[float targetMargin=0.1])

t2dVector is a 2d coordinate such as "0 0"
#2
11/16/2012 (12:53 pm)
It was the issue with the quotations, removing those and adding the SPC worked. Thanks !