Jump to content
Liberty Bull

AI random doMove Script quickly stops working?

Recommended Posts

I am using the script from this post here which uses the following code:
 

Spoiler

params ["_currentPos","_unit"]; //var name of starting position (game logic object), var name of patrolling unit (unit)

_lastPos = _currentPos;

while {true} do
{

    _synchPositions = synchronizedObjects _currentPos; //find all positions synchronized to the current position

    _nextPosArray = if (count _synchPositions > 1) then //check to ensure the unit does not backtrack unnecessarily
         {
              _synchPositions select {_x != _lastPos}
        } 
          else 
        {
              _synchPositions
        }; 
    
    _nextPos = selectRandom _nextPosArray; //randomly select another position to move to

    _unit doMove getPos _nextPos; //make AI walk towards the new position

    waitUntil {_unit distance getPos _nextPos < 1}; //wait until the AI has reached the new position
    
    _lastPos = _currentPos; //register the last position for the next loop to ensure no unnecessary backtracking

    _currentPos = _nextPos; //update current position
    
};

 

Being called by a trigger "On radio" with the following activation:

[var_startingLogic, var_logicUnit] spawn fnc_logic;

 

The unit and starting game logic are named appropriately, and the script works for less than a minute before after a random amount of points the unit simply stops. I am trying to get AI to move around inside custom composition interiors and this seemed like a simple solution, if I could get it to work long term.

 

I am pretty new to scripting, so I'm sure there is something glaringly obvious I'm missing.

 

Any help is greatly appreciated.
 

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

×