Game Development Community

what is the meaning by ((%this.right - %this.left) * %this.horizontalSpeed);

by jack518 · in Torque Game Builder · 09/02/2009 (10:49 pm) · 2 replies

Hi, I am working on Rainy Day tutorial, but some lines of codes shown next confuse me much.

function MovementBehavior::updateMovement(%this)
{
// make the player move
%this.owner.setLinearVelocityX((%this.right - %this.left) * %this.horizontalSpeed);
%this.owner.setLinearVelocityY((%this.down - %this.up) * %this.verticalSpeed);
}

#1
09/02/2009 (11:50 pm)
The Left/Right/Up/Down fields indicate whether or not their corresponding keys have been pressed. Lets go through some scenarios:
  • If Left is held down, then X-Axis velocity will be ( 0 - 1 ) * Speed.
  • If Right is held down, then X-Axis velocity will be ( 1 - 0 ) * Speed.
  • If both Left & Right are held down, the X-Axis velocity will be ( 1 - 1 ) * Speed.
Do the same for Up/Down and you should get the idea.
#2
09/03/2009 (1:35 am)
yes. ths, i just tested it.and indeed. got an idea of its work principle.