Sync Tutorial - Programming Player Movement
Make a new file in a text editor, e.g. notepad. DO NOT USE WORD PROSSESSORS!  If you are using notepad you have to select the type as All Files.
Save the file under MyGames/Sync/game/behaviors as Ship Movement.cs
Add this code to the file ShipMovement.cs.
if (!isObject(ShipMovementBehavior))
{
%template = new BehaviorTemplate(ShipMovementBehavior);
%template.friendlyName = "Ship Movement Controls";
%template.behaviorType = "Input";
%template.description = "Galaxy Wars Style Controls";
%template.addBehaviorField(upKey, "Key to bind to Upward Movement", keybind, "keyboard up");
%template.addBehaviorField(downKey, "Key to bind to Downward Movement", keybind, "keyboard down");
%template.addBehaviorField(leftKey, "Key to bind to rotate Left Movement", keybind, "keyboard left");
%template.addBehaviorField(rightKey, "Key to bind to rotate Right Movement", keybind, "keyboard right");
%template.addBehaviorField(acceleration, "Forward acceleration (world units per second)", float, 2.0);
%template.addBehaviorField(turnSpeed, "Velocity of turning (degrees per second)", float, 120.0);
%template.addBehaviorField(damping, "Amount to damp movement (percentage of velocity per second)", float, 1.0);
}
This code adds a new behavior that we can attach to an object in Torque. It also creates  variables which we can edit in the game engine without returning to our code.
Next Page
Previous Page
SyncImages.Zip