Game Development Community

TDN Platformer-like movement problem

by Philip Mansfield · in Torque Game Builder · 12/22/2005 (8:56 am) · 2 replies

This isn't actually a problem that I'm having with the TDN Platformer tutorial, just with bits of code I've nicked out of it for my own use. I'm using T2D v1.1 and here are the relevant bits of code:
function initPlayerControls()
{
	new ActionMap(playerMoveMap);
	playerMoveMap.bind(keyboard, left, "playerLeft");
	playerMoveMap.bind(keyboard, right, "playerRight");
	playerMoveMap.push();
}

function playerLeft(%val)
{
	$moveLeft = %val;
}

function playerRight(%val)
{
	$moveRight = %val;
}

 function updatePlayer()
{
   %moveX = ($moveRight - $moveLeft) * $player.speed;
   $player.setLinearVelocityX(%moveX);
}
Judging from the descriptive text in TDN, this method of keyboard control should help get over pressing two opposing directions at once and then coming to a halt once you release one of the keys.

However, from what I can make out, all it does is stop the player dead in his tracks as soon as he presses in the opposite direction (whilst still holding down the previous direction key).

The maths simply cancel each other out if you're moving you're moving one way and try to move directly opposite.

Have I missed a step?

#1
12/27/2005 (3:45 pm)
Just a little bump incase anyone missed it :)
#2
01/01/2006 (1:21 pm)
Hey Philip,

I could be completely wrong about this, but I think the way the movement was set up was intentional - that is, that the player will stop if trying to move in both directions. After all, going the same speed in opposite directions would result in going nowhere :) I think what works well with this setup is that the player will always move when one key is pressed, so flicking quickly between opposing directions won't accidentally cancel out the movement.

I realize this probably doesn't answer your question - sorry :) Did you end up finding a better way of handling the movement? I'd be interested in hearing it.

Chris