Sync Tutorial - Further Programming Player Movement
Scroll Down to the end of the file and add the following code:
function ShipMovementBehavior::updateMovement(%this)
{
%
this.owner.rotateTo(%this.TargetAngle, %this.turnspeed);
//rotates the ship in the direction of the keys by the amount specified by the field turn speed in Torque
if(%this.left + %this.right + %this.up + %this.down) // checks for input
{
%
this.owner.setImpulseForcePolar(%this.TargetAngle, %this.acceleration);
//sets one time force in the direction of keys pressed
}
}
Go into Torque Game Builder and press the play level button. Your ship should be flying around the screen when you press the arrow keys.
Congratulations you have made your Ship Movement Behavior:
This code can be recycled into your own project, and is great for top down games.
Next Page
Previous Page