Page MenuHomeFeedback Tracker

setPos doesn't always work reliably with AI units
New, NormalPublic

Description

When testing a script that is supposed to teleport units maintaining the current formation I ran into issues with it not being reliable even in singleplayer.

What I would expect to happen here is for each iteration of the script to set the units up neatly in a line but what happens is some units get this weird rubberbanding effect and are not teleported to the new position

This isn't a video of the exact repro but it is a similar script that is trying to neatly teleport units
https://streamable.com/ypcae

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 11 x64
Category
Scripting
Steps To Reproduce

Start repro mission and it will attempt to teleport all AI units between a line along the X or Y axis every 2 seconds
You can see a portion of the units always get left behind at their previous position when they should be neatly teleported in line

Repro mission

Additional Information

Game version: 2.12.150512

The script is fairly simple:

DEV_STOP = false;

[] spawn {
    private _fn_SetupA = {
        params ["_units", "_centerPos"];

        private _spacing = 10;

        for "_i" from 0 to (count _units - 1) do {
            private _unit = _units select _i;
            private _pos = [(_centerPos select 0) + (_i * _spacing), _centerPos select 1, 0];
            _unit setPos _pos;
        };
    };

    private _fn_SetupB = {
        params ["_units", "_centerPos"];

        private _spacing = 10;

        for "_i" from 0 to (count _units - 1) do {
            private _unit = _units select _i;
            private _pos = [_centerPos select 0, (_centerPos select 1) + (_i * _spacing), 0];
            _unit setPos _pos;
        };
    };

    private _centerPos = getMarkerPos "spawnpos";
    private _units = allUnits - [player];

    private _flip = false;
    while {!DEV_STOP} do {
        if (_flip) then {
            [_units, _centerPos] call _fn_SetupA;
            _flip = !_flip;
        } else {
            [_units, _centerPos] call _fn_SetupB;
            _flip = !_flip;
        };
        sleep 2;
    }
};

Event Timeline

JonBons2020 updated the task description. (Show Details)Apr 19 2023, 1:19 PM
JonBons2020 edited Steps To Reproduce. (Show Details)
dedmen set Ref Ticket to AIII-55658.Apr 19 2023, 2:19 PM