Arma 3
Not enough ratings
How to Script Tank Turret Rotation in Arma 3
By SuperBrat12
You won't be able to use the editor, but you can utilize a script. Here's one that works for me.

Explanation of how it works:
Name the Tank: In the editor, name your tank under the "edit" and "variable name" fields.

Assign AI to the Turret: Place an AI inside the turret and give it a name under the "variable name" field as well.

Set the Target Location: You’ll need to provide the AI with a location to look at. To do this, place an object at a random position. Then, go into the object's properties and note down its X, Y, and Z coordinates.

Script Behavior: Once you've completed these steps, the script will rotate the turret to face the desired location, and then it will delete the AI.

In my script:

Ps1 represents the tank.
As1 represents the AI.

By some reason the script only works if there is the // for comments!

The Script is an .sqf

Script:
As1 moveInGunner Ps1;
Ps1 engineOn false;

As1 moveInGunner Ps1;//
Ps1 engineOn false; //

//
_targetPos = [5678.245, 1491.062, 4.433];
As1 doWatch _targetPos;

//
[this] spawn {
sleep 2; // Give AI time to aim
deleteVehicle As1; // Remove AI, locking turret
};


IF THIS SCRIPT DIDNT WORK HERE IS A MORE COMPLICATED ONE BUT IT WORKS 100% everytime!

Here's how the script works: You add an object and give it a random name (in my script, I named it Po1). The gunner will then locate the object and rotate the turret toward it. After 2 seconds, the AI gunner will be deleted, along with the object used as a pointer. This method works every time!

As1 moveInGunner Ps1;
Ps1 engineOn false;

As1 setSkill ["aimingSpeed", 1];
As1 setSkill ["aimingAccuracy", 1];

As1 doTarget Po1;
As1 doWatch Po1;

[this] spawn {
private _lastDir = (Ps1 weaponDirection currentWeapon Ps1); // Initial turret direction
private _timeStopped = 0;

while {true} do {
sleep 0.5; // Check every 0.5 seconds

private _currentDir = (Ps1 weaponDirection currentWeapon Ps1);


if !(_currentDir isEqualTo _lastDir) then {
_timeStopped = 0;
} else {
_timeStopped = _timeStopped + 0.5;
};

_lastDir = _currentDir;


if (_timeStopped >= 2) exitWith {
deleteVehicle As1;
deleteVehicle Po1;
};
};
};



   
Award
Favorite
Favorited
Unfavorite
Image of Script
Here is a image of the script
3 Comments
SuperBrat12  [author] 22 Mar @ 8:04am 
No, you do not put this script in the init of the driver (As1). Instead, you save it as an SQF file (e.g., turretLock.sqf) and execute it from the init of the mission or another trigger.

1. Save the Script as an SQF File
Open Notepad (or a text editor).

Copy one of the scripts (basic or advanced).

Save it as turretLock.sqf (make sure it's .sqf and not .txt).

Place the file inside your mission folder:
C:\Users\YourName\Documents\Arma 3\missions\YourMissionName\

You need to run the script using execVM.

in your mission add a trigger and use this command in it : execVM "turretLock.sqf";
Stormtrippin 22 Mar @ 7:42am 
Do you put this script in the init of the driver (As1)?
SuperBrat12  [author] 8 Feb @ 9:15am 
Couldn't find anything online about controlling a tank turret's position in Arma 3, so here's a script that does it! I hope this helps those who need it!:RedStar: