Search the Community
Showing results for tags 'setDir'.
Found 5 results
-
How to constantly spin/rotate an object in Multiplayer
ConPrice posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hi everyone! ( This is a repost, because I have some debug and video demo) I have a problem. I have been trying to create a script that will let me spin/rotate an object real fast. The object in question is LightHouse (tall) (Land_LightHouse_F). But I had one problem. the lighthouse's pivot point is at its door, not at its centre. So I have been using this code. Which got rid of the problem of lighthouse spinning around its door instead of its centre: params ["_objectToSpin", "_spinSpeedMin", "_spinSpeedMax", "_timeToReachMaxSpeed"]; // Initialize parameters _spinSpeedMin = _spinSpeedMin; // Initial rotation speed in degrees per second _spinSpeedMax = _spinSpeedMax; // Maximum rotation speed in degrees per second _timeToReachMaxSpeed = _timeToReachMaxSpeed; // Time to reach maximum speed in seconds // Get the initial position of the object _initialPosition = position _objectToSpin; // Ensure the object is initially on the ground _initialPosition set [2, (_initialPosition select 2) + 0.1]; _objectToSpin setPos _initialPosition; // Calculate model's center offset (adjust these values based on your model's pivot) _modelCenter = [0, 0, 0]; // Replace with the actual offset if known // Initialize rotation and time _lastTime = diag_tickTime; _startTime = _lastTime; // Record the start time _initialHeight = (_initialPosition select 2); _currentRotationSpeed = _spinSpeedMin; // Initial rotation speed // Main loop to handle rotation while {alive _objectToSpin} do { _currentTime = diag_tickTime; _deltaTime = _currentTime - _lastTime; // Calculate elapsed time since start _elapsedTime = _currentTime - _startTime; // Calculate current rotation speed based on elapsed time if (_elapsedTime < _timeToReachMaxSpeed) then { _currentRotationSpeed = _spinSpeedMin + (_spinSpeedMax - _spinSpeedMin) * (_elapsedTime / _timeToReachMaxSpeed); } else { _currentRotationSpeed = _spinSpeedMax; }; // Calculate new rotation angle _rotationIncrement = _currentRotationSpeed * _deltaTime; _currentDir = getDir _objectToSpin; _newDir = _currentDir + _rotationIncrement; _newDir = _newDir % 360; // Ensure the angle stays within 0-360 degrees // Calculate the current position _currentPos = position _objectToSpin; _newPos = [ (_currentPos select 0) - (_modelCenter select 0), (_currentPos select 1) - (_modelCenter select 1), _initialHeight // Maintain consistent height ]; // Apply rotation _objectToSpin setDir _newDir; // Set the new position _objectToSpin setPos [_newPos select 0, _newPos select 1, _newPos select 2]; _lastTime = _currentTime; // Update the last time // Sleep to yield to other processes sleep 0.01; }; This script was working fine until I tested it on a dedicated server. On a dedicated server lighthouse spins around its door instead of its centre. I am not good at math, so most of the code is just bits and pieces I got from the internet and put together. I call the script this way: I have an object with addAction: this addaction["Spin it", { [_this select 0,_this select 2] remoteExec ["removeAction", 0, true]; null = [] execVM "scripts\end.sqf"; }, [], 6, false, true, "", "", 5]; and end.sqf has the line: null = [object_to_levitate, 0, 120, 20] execVM "scripts\spin.sqf"; at the top. I don't know how to solve this issue. I appreciate any help. Video demonstration of what is happening instead of what is supposed to happen: I run the code with debug messages: Singleplayer: Current position : [8684.5,10613.9,0.1], New position after adjustment: [8684.5,10613.9,0.1] Object rotated to NewDir = 284.013 and moved to NewPos = [8684.5,10613.9,0.1] and position numbers never change. They stay the same. Only things that change are direction, rotations speed/increment and elapsed time. And this is the result when I run this mission on multiplayer server: Current position : [8683.16,10611.3,0.1], New position after adjustment: [8683.16,10611.3,0.1] Object rotated to NewDir = 324.629 and moved to NewPos = [8683.14,10611.2,0.1] Notice the difference between position numbers? And positions numbers constantly change unlike single player where they would stay constant. -
Hi, I cannot find what command to use to make an attack heli to face certain position while flying with "SAD" waypoint. I spawn it and add waypoints with this /* _mrk is the flag marker, string _heli is the attack helicopter className, string _arrival is the time from zone activation to spawning the attack heli, integer _force is how many attack helicopter will come one after another, integer */ params ["_mrk", "_heli","_arrival","_force"]; for "_i" from 0 to _force do { sleep _arrival; deleteVehicle attackHeli; {deleteVehicle _x} forEach units attackHeliGRP; _atkHeliPos = [[[(getMarkerPos _mrk),4000]], [[(getMarkerPos _mrk),3000]]] call BIS_fnc_randomPos; _attackPosA = [[[(getMarkerPos _mrk),400]], []] call BIS_fnc_randomPos; _attackPosA set [2, 200]; _attackPosB = [[[(getMarkerPos _mrk),400]], []] call BIS_fnc_randomPos; _attackPosB set [2, 200]; _attackPosC = [[[(getMarkerPos _mrk),400]], []] call BIS_fnc_randomPos; _attackPosC set [2, 200]; private _delPos = [[[(getMarkerPos _mrk),4000]], [[(getMarkerPos _mrk),3000]]] call BIS_fnc_randomPos; _delPos set [2, 200]; attackHeliGRP = createGroup [west, true]; attackHeli = createVehicle [_heli, _atkHeliPos, [], 0, "FLY"]; attackHeliGRP createVehicleCrew attackHeli; attackHeliGRP setBehaviourStrong "COMBAT"; attackHeli flyInHeight 200; attackHeli limitSpeed 100; private _wp1 = attackHeliGRP addWaypoint [_attackPosA, 0]; _wp1 setWaypointType "SAD"; _wp1 setWaypointTimeout [60, 120, 60]; private _wp2 = attackHeliGRP addWaypoint [_attackPosB, 0]; _wp2 setWaypointType "SAD"; _wp2 setWaypointTimeout [60, 120, 60]; private _wp3 = attackHeliGRP addWaypoint [_attackPosC, 0]; _wp3 setWaypointType "SAD"; _wp3 setWaypointTimeout [60, 120, 60]; private _wp3 = attackHeliGRP addWaypoint [_delPos, 0]; _wp3 setWaypointType "MOVE"; _wp3 setWaypointStatements ["true", "deleteVehicleCrew attackHeli; deleteVehicle attackHeli; deleteGroup attackHeliGRP;"]; sleep _arrival; }; I wonder how to change direction if flying object so when the AH64 wait for the next waypoint to face the position it has to defend and the gunner can search for infantry targets, etc.
-
I'm having a couple of snipers (same group) reach their spot and then keep watch over a static position (in the image below represented by the lighthouse). What we noticed is that the more distant the lighthouse, the more untidy the "distracted" snipers' direction in relation to the position (lighthouse) they were supposed to be watching. I've given many go to align the group leader's position but the image was my best. Here are some commands that I've already tried: setDir, getDir, setFormDir. But doWatch and lookAt work better and, of course, because of the purpose, I chose to use doWatch. initServer.sqf (just for testing): waitUntil { !isNull grp1 }; private _sniperPos = [3801.55,4266.83,0]; private _wp = grp1 addWaypoint [_sniperPos, 0]; waitUntil {sleep 0.2; ((leader grp1) distance _sniperPos) < 8 }; grp1 setBehaviourStrong "AWARE"; grp1 setSpeedMode "LIMITED"; { _x setUnitPos "DOWN" } forEach (units grp1); systemChat format ["Before formationDirection '%1'", formationDirection (leader grp1)]; waitUntil {sleep 3; ((leader grp1) distance _sniperPos) < 1 }; { sleep 2; //[_x, (_x getDir LIGHTHOUSE)] remoteExec ["setDir"]; //_x setDir (_x getDir LIGHTHOUSE); //[_x, (_x getRelDir LIGHTHOUSE)] remoteExec ["setDir"]; //_x setDir (_x getRelDir LIGHTHOUSE); _x doWatch LIGHTHOUSE; } forEach (units grp1); grp1 setFormation "DIAMOND"; // better than LINE 'cause the spotter doesn't get in the sniper's way most of the time. grp1 setFormDir (getDir (leader grp1)); while { true } do { ["behaviour '%1' / formationDirection '%2' / eyeDirection '%3' / ", behaviour (leader grp1), formationDirection (leader grp1), eyeDirection (leader grp1)] call BIS_fnc_error; sleep 2; }; Demo: https://drive.google.com/file/d/18QGkzuj53y4LwcPvxpYBASMhiQROB76a/view?usp=sharing If you got some more to share, please, keep going!
-
Hey everybody! I have saved 4 different positions and their relative directions to spawn a unit, but unit's direction never matches the one I saved. First, this is the code I am using: _pos = [ [3144.13,3984.86,1.24656], [3148.41,3982.62,1.1283], [3148.64,3979.73,1.10767], [3153.13,3977,1.0178] ]; _dir = [16.0291,308.932,328.367,320]; _dice = count _pos; _dice = floor (random _dice); _grp = createGroup EAST; _unit = _grp createUnit ["O_G_Soldier_F", markerPos "marker", [], 0, "NONE"]; _unit setPosATL (_pos select _dice); sleep 1; _unit allowFleeing 0; _unit setDir(_dir select _dice); _unit setUnitPos "MIDDLE"; I check unit's direction after it's creation with _dirTarget = getDir cursorTarget; hint str(_dirTarget); For example my last 3 spawns: Instead of 308.9 it's 338.9 Instead of 328.3 it's 358.3 Instead of 16.02 it's 0.011 How is that possible and how am I able to stop this behaviour? It's driving me crazy, because I need them quite accurate. I tried with different sleep values, with and without allowFleeing or setUnitPos. I don't get it. Kind Regards.
- 2 replies
-
- setDir
- setFormDir
-
(and 1 more)
Tagged with:
-
how to make an array with setPosATL & setDir positions for MP respawn ?
doomnet posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
hello, i have made some positions with setPosATL and setDir this setPosATL [16559.8,21846.6,1.13549]; this setDir 271.228; this setPosATL [16560.2,21848.7,1.10291]; this setDir 279.611; this setPosATL [16556.1,21847.2,0.573884]; this setDir 3.74775; this setPosATL [16556.8,21850.9,0.636226]; this setDir 268.757; how to make an array to use in this code for random respawn positions ? if (isServer) then { _randomPos = [,,,,] call BIS_fnc_selectRandom; player setPos (getPos _randomPos); }; i found a lot of answers for making an array but not for multiple setPos and setDir positions in one array !