Q about Basic Tutorial
by Jason McIntosh · in Torque Game Builder · 02/27/2005 (10:33 am) · 3 replies
In the basic tutorial, it mentions this function:
...and how it avoids some "subtle bugs" with the if() statement. I'm just curious what subtle bugs this refers to. Trying to get a deeper understanding of the engine than what's in the docs ATM.
Thanks!
/-----------------------------------------------------------------------------
// Player Up (Stop).
//-----------------------------------------------------------------------------
function playerUpStop()
{
// If we're moving up then nullify any upward movement.
if ( $player.getLinearVelocityY() < 0 )
$player.setLinearVelocityY( 0 );
}...and how it avoids some "subtle bugs" with the if() statement. I'm just curious what subtle bugs this refers to. Trying to get a deeper understanding of the engine than what's in the docs ATM.
Thanks!
About the author
#2
02/27/2005 (11:26 am)
Try it, you can definitely see what happens if you don't put in the if statement. Attempt to rapidly switch between up and down or right and left and you will be unable to move while the key is held.
Torque Owner Jason Cahill
Default Studio Name
Up released (linear velocity is now 0)
Down pressed (linear velocity is now 10)
then everything would be fine. Reverse them:
Down pressed (linear velocity is now 10)
Up released (linear velocity is now 0) ** Whoops! **
This isn't a bug in the engine. They are just making an elegant solution to the problem above with the ifs.