setVelocityTransformation: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) mNo edit summary |
Killzone Kid (talk | contribs) No edit summary |
||
Line 81: | Line 81: | ||
]; | ]; | ||
};</code> |= Example 2 | };</code> |= Example 2 | ||
|x3= Advanced trickery with curved movement:<code>[[disableSerialization]]; | |||
[[player]] [[setDir]] 0; | |||
interval = 0; | |||
_disp = [[findDisplay]] 46 [[createDisplay]] "RscDisplayEmpty"; | |||
_ctrl = _disp [[ctrlCreate]] ["RscSlider", -1]; | |||
_ctrl [[ctrlSetPosition]] <nowiki>[</nowiki>[[safeZoneX]] + 0.1, 1, [[safeZoneW]] - 0.2, 0.1]; | |||
_ctrl [[ctrlSetActiveColor]] [1, 0, 0, 1]; | |||
_ctrl [[ctrlCommit]] 0; | |||
_ctrl [[sliderSetPosition]] 0; | |||
_ctrl [[sliderSetRange]] [0, 1]; | |||
_ctrl [[sliderSetSpeed]] [0.1, 0.5]; | |||
_ctrl [[ctrlAddEventHandler]] ["SliderPosChanged", {interval = [[_this]] [[select]] 1}]; | |||
[[ctrlSetFocus]] _ctrl; | |||
box = "Land_VR_Shape_01_cube_1m_F" [[createVehicle]] [0,0,0]; | |||
fromControlPointOffset = [-50, 50, 30]; | |||
fromPosASL = [[AGLtoASL]] ([[player]] [[getRelPos]] [10, -45]); | |||
toControlPointOffset = [50, 50, 30]; | |||
toPosASL = [[AGLtoASL]] ([[player]] [[getRelPos]] [10, 45] [[vectorAdd]] toControlPointOffset); | |||
[[onEachFrame]] | |||
{ | |||
[[hintSilent]] [[format]] ["Interval: %1", interval]; | |||
box [[setVelocityTransformation]] | |||
[ | |||
fromPosASL [[vectorAdd]] (fromControlPointOffset [[vectorMultiply]] interval), | |||
toPosASL [[vectorDiff]] (toControlPointOffset [[vectorMultiply]] interval), | |||
[0,0,0], | |||
[0,0,0], | |||
[0,1,0], | |||
[1,0,0], | |||
[0,0,1], | |||
[0,1,0], | |||
interval | |||
]; | |||
};</code> |= Example 3 | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
Revision as of 21:14, 17 December 2018
Description
- Description:
- Interpolates and applies PositionASL, velocity, vectorDir and vectorUp to the given object based on the interval value.
When interval is 0 the "fromXXX" values are used for the beginning of the interpolation. When interval is 1, the "toXXX" values are used for the end of interpolation. When interval value is in between, interpolated values are used (see diagram below). The interpolation is linear and along straight line between "from" and "to" positions. If curve is needed, then it should be constructed from multiple straight sections or by dynamically changing value of position params during the interpolation cycle (advanced trickery).
The velocity param doesn't do much in SP, but in MP, provided the velocity component is set correctly, it helps the engine to figure out what the next position of the moving object should be on other clients.
- Groups:
- Uncategorised
Syntax
- Syntax:
- object setVelocityTransformation [fromPosASL, toPosASL, fromVelocity, toVelocity, fromVectorDir, toVectorDir, fromVectorUp, toVectorUp, interval]
- Parameters:
- object: Object - object to be interpolated
- [fromPosASL, toPosASL, fromVelocity, toVelocity, fromVectorDir, toVectorDir, fromVectorUp, toVectorUp, interval] : Array
- fromPosASL: PositionASL - starting getPosASL of the object
- toPosASL: PositionASL - ending getPosASL of the object
- fromVelocity: Array - starting velocity of the object
- toVelocity: Array - ending velocity of the object
- fromVectorDir: Array - starting vectorDir of the object
- toVectorDir: Array - ending vectorDir of the object
- fromVectorUp: Array - starting vectorUp of the object
- toVectorUp: Array - ending vectorUp of the object
- interval: Number - interpolation interval (variable value, normally between 0 and 1)
- Return Value:
- Nothing
Examples
- Example 1:
_tracker setVelocityTransformation [ getPosASL _currentPos, getPosASL _nextPos, velocity _currentVelocity, velocity _nextVelocity, vectorDir _currentVectorDir, vectorDir _nextVectorDir, vectorUp _currentVectorUp, vectorUp _nextVectorUp, _timeDiff ];
- Example 2:
- Bob on imaginary stairway to heaven:
bob = createAgent ["C_man_1", player getRelPos [5, 0], [], 0, "CAN_COLLIDE"]; bob switchMove "ladderciviluploop"; pos1 = getPosASL bob; pos2 = pos1 vectorAdd [0,0,0.75]; bob addEventHandler ["AnimDone", { pos1 = pos2; pos2 = pos2 vectorAdd [0,0,0.75] }]; onEachFrame { if (!alive bob) then { onEachFrame {}; bob switchMove ""; bob removeAllEventHandlers "AnimDone"; }; bob setVelocityTransformation [ pos1, pos2, [0,0,0], [0,0,0], [0,1,0], [0,1,0], [0,0,1], [0,0,1], moveTime bob ]; };
- Example 3:
- Advanced trickery with curved movement:
disableSerialization; player setDir 0; interval = 0; _disp = findDisplay 46 createDisplay "RscDisplayEmpty"; _ctrl = _disp ctrlCreate ["RscSlider", -1]; _ctrl ctrlSetPosition [safeZoneX + 0.1, 1, safeZoneW - 0.2, 0.1]; _ctrl ctrlSetActiveColor [1, 0, 0, 1]; _ctrl ctrlCommit 0; _ctrl sliderSetPosition 0; _ctrl sliderSetRange [0, 1]; _ctrl sliderSetSpeed [0.1, 0.5]; _ctrl ctrlAddEventHandler ["SliderPosChanged", {interval = _this select 1}]; ctrlSetFocus _ctrl; box = "Land_VR_Shape_01_cube_1m_F" createVehicle [0,0,0]; fromControlPointOffset = [-50, 50, 30]; fromPosASL = AGLtoASL (player getRelPos [10, -45]); toControlPointOffset = [50, 50, 30]; toPosASL = AGLtoASL (player getRelPos [10, 45] vectorAdd toControlPointOffset); onEachFrame { hintSilent format ["Interval: %1", interval]; box setVelocityTransformation [ fromPosASL vectorAdd (fromControlPointOffset vectorMultiply interval), toPosASL vectorDiff (toControlPointOffset vectorMultiply interval), [0,0,0], [0,0,0], [0,1,0], [1,0,0], [0,0,1], [0,1,0], interval ]; };
Additional Information
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Notes
- Posted on Aug 4, 2014 – 12:35
- ffur2007slx2_5
-
(A3 1.24) Generally speaking setVelocityTransformation is more likely a combination of setPosASL, setVectorDirAndUp (or BIS_fnc_setPitchBank) and time multiplier. It can be used as a position tracker with all necessary information collected, copied and then released within one function. Here’s a simple reproduction on how setVelocityTransformation works in game:
private ["_dataOld","_dataNext","_capturedData","_obj","_fps","_startTrackingTime","_stepOld","_stepNext","_tracker","_tempTime"]; _stepOld = 0; _tempTime = 0; _stepNext = 1; while {true} do { _capturedData = _capturedData + [[ getPosASL _obj,velocity _obj,vectorDir _obj,vectorUp _obj]]; sleep _fps; _tempTime = _tempTime + _fps; if (_tempTime >= _startTrackingTime) then { _dataOld = _capturedData select _stepOld; _dataNext = _capturedData select _stepNext; _stepOld = _stepOld + 1; _stepNext = if (_stepNext >= (count _capturedData)) then [{_stepOld},{_stepNext + 1}]; _tracker setVelocityTransformation [_dataOld select 0,_dataNext select 0,_dataOld select 1,_dataNext select 1, _dataOld select 2,_dataNext select 2,_dataOld select 3,_dataNext select 3,1]; }; };
Tracker starts coping the route and stance from the object when time start counting. TimeDiff determines the distance multiply between the current position and the next position.
Bottom Section
Categories:
- Scripting Commands
- Introduced with Arma 2: Operation Arrowhead version 1.51
- Arma 2: Operation Arrowhead: New Scripting Commands
- Arma 2: Operation Arrowhead: Scripting Commands
- Command Group: Uncategorised
- Scripting Commands: Global Effect
- Scripting Commands ArmA2
- Scripting Commands Arma 3
- Scripting Commands Take On Helicopters
- ArmA 2 OA: New Scripting Commands List