Jump to content
avibird 1

How to get a unit to continuously rotate 180 ?

Recommended Posts

In Arma2 I had a snippet of code that I put into the unit init.box that allowed my units standing guard the ability to rotate 180 during a mission. I can't find my code I used to see if it will work in Arma3. Does anyone know what I need to place in the  initial to get a unit rotate.

Share this post


Link to post
Share on other sites

this is my code in a movegunner.sqf

 

//Obj is the unit searching 0-359;
//deg is the area that the unit will search;
// null=[obj,deg] execVM "movegunner.sqf


_unit = _this select 0;
_deg is this select 1;

_face = getdir _unit
_gman = (gunner (vehicle _unit));

while {(alive _gman) && (alive _unit)} do
{ _gman setformdir _face+ (( random - (_deg) +(_deg/2)));

sleep (random 6) +2; };

 

 

this is in my unit init  null= [this,120] execVM "movegunner.sqf

 

 

Worked fine in ARMA2 ANY help would be great.

Share this post


Link to post
Share on other sites

I do not know of any single command that will nicely transition from facing one direction to the other. That being said, this may be simulated using getDir and setDir. 

 

In unit's init field:

null = [this] execVM "script.sqf";

script.sqf

_unit = _this select 0;
while {sleep 180; (behaviour _unit != "COMBAT")} do {
	//Every 3 minutes, if unit is not in combat, execute rotation which involves 18 movements of 10 degrees for 180 degrees in about 2 seconds
	for "_i" from 1 to 18 do 
	{
		_unit setDir ((getDir _unit) + 10);
		sleep 0.15;
	};
};

//Wait for unit to be out of combat
waitUntil {behaviour _unit != "COMBAT"};

//Reset the rotation script
[_unit] execVM "script.sqf";

It is a bit of a workaround, but it follows the logic of what you are trying to achieve. I don't have my game available, so not sure how funny the above looks.

 

Regarding your code not working, assuming you copy/pasted it...

_deg is not defined correctly

_face definition statement does not end with semi colon

You should enable showScriptErrors.

 

So after that, what is not working about your code? If setFormDir is doing what you are wanting smoothly, that is awesome, and far superior to my inefficient suggestion. Haven't used that command before, thanks for sharing. 

Share this post


Link to post
Share on other sites

Thank you I will gave you code a try.

 

How should my _deg be defined

_face what does it end with then? 

 

Thank you .

Share this post


Link to post
Share on other sites

Numerous fixes.

 

movegunner.sqf

//Obj is the unit searching 0-359;
//deg is the area that the unit will search;
//null=[obj,deg] execVM "movegunner.sqf";


_unit = _this select 0;
_deg = _this select 1;

_face = getDir _unit;
_gman = (gunner (vehicle _unit));

while {(alive _gman) && (alive _unit)} do
{ 
	_gman setFormDir _face + (random - (_deg) + (_deg/2));
	sleep (random 6) + 2;
};

 

Share this post


Link to post
Share on other sites

 

26 minutes ago, KC Grimes said:

Numerous fixes.

 

 

Hey KC Grimes I can't get both of them to work. My adjusted code that you did and the new one your provided both don't work :eh:

Share this post


Link to post
Share on other sites

Are you looking to have them snap around 180 quickly? Or just rotate casually while they stand guard? Because using BIS_fnc_ambientAnimCombat with the animation "WATCH" causes the unit to casually turn around and check basically every direction.

Edit: I see the script has the word gunner in it, so maybe you're trying to get turrets to move, I'm not sure because you said standing guard, so I apologize if this is completely useless for what you want.

  • Like 1

Share this post


Link to post
Share on other sites

This is definitely strange. I was able to get turrets to do exactly this back in A2, but now in A3 I can't seem to get setFormDir to work with turrets at all.

Share this post


Link to post
Share on other sites

Nothing is useless lol. All information  and knowledge is only Plus with anything to do with this game and attempting to script for it. 

 

I have a few  machine guns turrets and Soldier units with flashlights on their rifles. Next to the guns.  It seems Arma3 does not have the ARMA2 Searchlight  that could rotate with code inside it's init. Box. I can't find the ARMA2 Searchlight in cup items? 

 

The Arma3 searchlights are static In Design and I don't think even with the right code you could not get it to rotate.

 

The lighting is far superior in Arma 3 than in arma2 but for the life of me can't understand why boheima did not include a working Searchlight in the vanilla Arma3. 

 

Need help on this right now using two tall lighthouses on either side of my pow camp looks awesome but would like to remove one of them which is not on the water side. 

Share this post


Link to post
Share on other sites

Simple Guard Post Script v1.0

by Tophe of Östgöta Ops [OOPS]

>> ARMAHOLIC DOWNLOAD <<

This script will have the AI randomly look around instead of just looking in one direction.

Putting this on a searchlight really adds to the immersion during night missions.

You may set the range of degrees for the guarding unit.

It is also possible to set behaviour, stance, height range and delay.

To run with default settings, just put this in the units init line:

nul = [this] execVM "GuardPost.sqf"

OPTIONS

There are some optional settings. The format for these are:

nul = [unit, range, behaviour, stance, up/down, delay] execVM "GuardPost.sqf"

If you don't set anything the default settings will be used, they look like this:

nul = [this, 240, "SAFE", "AUTO", false, 1] execVM "GuardPost.sqf"

Range:

The scanning range of the unit , 0 to 360 degrees. The unit will keep it's original direction as middle and scan.

So if you have a guard with azimut 0, and want it to scan 180 degrees - the unit will be looking between

270 and 90 degrees (90 degrees in each direction).

Example: nul = [this,180] execVM "GuardPost.sqf"

Behaviour:

Set the starting behaviour of the unit. Possible settings are CARELESS, SAFE, AWARE, COMBAR, STEALTH.

If you want the unit to have his weapon rested while looking, set it to SAFE. If you want the unit to aim while

looking set it to "COMBAT". You must use quotations.

Example: nul = [this,180,"COMBAT"] execVM "GuardPost.sqf"

Stance:

You may force the unit to stay in a certain stance with this setting.

Possible settings are:

UP - the unit will keep standing even when being shot at. Good for towers.

MIDDLE - the unit will stay kneeling. Good for units behind standard sand bag walls.

DOWN - the unit will stay in prone position. Good for snipers etc.

AUTO - the unit will change stance according to the situation.

Example: nul = [this,180,"COMBAT","UP"] execVM "GuardPost.sqf"

Up/Down:

By default the unit will look straight forward. By setting this to TRUE you can have it look upward aswell, on rooftops, hills etc.

This is very good for search lights, since they will cover a much greater area and also scan for choppers.

Possible setting are TRUE or FALSE

Example: nul = [this,180,"COMBAT","UP",true] execVM "GuardPost.sqf"

Delay:

The unit wait a short moment before changing direction. Here you may enter the shortest amount of time you want for this delay.

The unit will then wait between this value and the value + 10 seconds. If you want it to wait between 10 and 20 seconds you enter this...

Example: nul = [this,180,"COMBAT","UP",true, 10] execVM "GuardPost.sqf"

Edited July 13, 2010 by Tophe

Share this post


Link to post
Share on other sites

setFormDir worked on the the unit in the turret in A2 not the turret.

 

The lights in A3 have no crew so it can't work, even trying it on a static gunner yields  no results in A3 so they have removed the option.

 

 

Just digging through some old code I found this, it attaches  the A3 light to a turret  (tank or static gunner ect)

 

SearchLight1 attachTo [st1, [0,0,0.3], "OsaVeze"];     
addMissionEventHandler ["Draw3D", {   
 SearchLight1 setVectorDirAndUp [   
  (st1 selectionPosition "usti hlavne") vectorFromTo (st1 selectionPosition "OsaHlavne"),    
  [0,0,1]   
 ];   
}];

You can then make the static gunner invisible just leaving the light.

 

To rotate it  use something like this st1 being the static turret, to keep it moving it will need to be in a loop of course.

It may not work in MP but I never tested it.

 

st1 dowatch ( st1 modelToWorld  [-200 + (random 400),100,0])

 

For a better light there is an addon at Armaholic  I think.

  • Thanks 1

Share this post


Link to post
Share on other sites

For future reference...

The script I posted was intended to rotate a unit "casually" a certain amount of degrees to imitate a "watch". It appears as cumbersome as the script looks unfortunately. For this purpose, @Mynock's suggestion of BIS_fnc_ambientAnimCombat was absolutely perfect and transitions straight into combat as needed, and can be transitioned back into with scripting. I would recommend this for any sort of "watching" by soldiers.

 

That being said, I now understand what the OP is trying to do, and it is not this :P

 

Verified that setFormDir did not seem to affect  turret gunners (particularly that of a tank). Actually did not seem to affect anything about the tank after executing in different ways (on different crew and the vehicle itself). doWatch in its place, however, provided the intended effect with a smooth transition. If the logic of my initial script suggestion were to be used, I would recommend replacing setDir with doWatch. If no particular pattern of "watching" was desired, I would again recommend the use of BIS_fnc_ambientAnimCombat above all else. 

 

Thanks @f2k sel

  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×