Learn TORQUE3D with Real Code Examples
Updated Nov 24, 2025
Code Sample Descriptions
1
TorqueScript Example - Simple Player Movement
// Define player controls
moveMap.bindCmd(keyboard, "a", "moveleft();", "stopmoveleft();");
moveMap.bindCmd(keyboard, "d", "moveright();", "stopmoveright();");
function moveleft() {
$mvLeftAction = 1;
}
function stopmoveleft() {
$mvLeftAction = 0;
}
function moveright() {
$mvRightAction = 1;
}
function stopmoveright() {
$mvRightAction = 0;
}
A simple TorqueScript snippet showing how to move a player object using key inputs.
2
TorqueScript Example - Jump Action
// Bind jump key
moveMap.bindCmd(keyboard, "space", "jump();", "stopjump();");
function jump() {
$mvUpAction = 1;
}
function stopjump() {
$mvUpAction = 0;
}
Player jump action with key press.
3
TorqueScript Example - Shooting Projectile
// Bind shoot key
moveMap.bindCmd(keyboard, "ctrl", "shoot();", "stopshoot();");
function shoot() {
%proj = new Projectile() {
position = Player.getPosition();
velocity = "0 50 0";
};
}
function stopshoot() {
// Nothing for now
}
Player shooting a projectile on key press.
4
TorqueScript Example - Health Management
// Increase health
function addHealth(%amount) {
$PlayerHealth += %amount;
if ($PlayerHealth > 100) $PlayerHealth = 100;
}
// Decrease health
function removeHealth(%amount) {
$PlayerHealth -= %amount;
if ($PlayerHealth < 0) $PlayerHealth = 0;
}
Increase or decrease player health.
5
TorqueScript Example - Score System
// Initialize score
$PlayerScore = 0;
function collectItem() {
$PlayerScore += 10;
echo("Score: " @ $PlayerScore);
}
Simple scoring system for collecting items.
6
TorqueScript Example - Teleport Player
function teleportPlayer(%x, %y, %z) {
Player.setPosition(%x SPC %y SPC %z);
}
// Example teleport
teleportPlayer(0, 0, 10);
Teleport player to a specific location.
7
TorqueScript Example - Spawn Enemy
function spawnEnemy(%x, %y, %z) {
%enemy = new AIPlayer() {
position = %x SPC %y SPC %z;
};
}
spawnEnemy(20, 0, 0);
Spawns an enemy at a location.
8
TorqueScript Example - Toggle Light
function toggleLight(%light) {
if (%light.isEnabled()) {
%light.setEnabled(false);
} else {
%light.setEnabled(true);
}
}
// Toggle example
toggleLight(MyLight);
Toggles a light on/off.
9
TorqueScript Example - Simple Timer
// Schedule function after 3 seconds
schedule(3000, 0, "timerEvent");
function timerEvent() {
echo("Timer finished!");
}
Basic timer example calling a function after a delay.
10
TorqueScript Example - Player Animation Trigger
// Bind animation key
moveMap.bindCmd(keyboard, "e", "playAnimation();", "stopAnimation();");
function playAnimation() {
Player.playThread(0, "Wave");
}
function stopAnimation() {
Player.stopThread(0);
}
Trigger player animation on key press.