Jump to content
Smart Games

force spawned Ai to move on roads

Recommended Posts

Hi there, 

I want to create some Ai units which drive on roads from one position to another in a cycle.

 

I managed to spawn them, but can't make them move. 

I tried calculatepath, setDestination, forcefollowroad and waypoints.

 

spawn code (works fine):

  private _pos1 = [_center, 5, _axis, 3, 0, 20, 0] call BIS_fnc_findSafePos;
  private _road1 = [_pos1, 500] call BIS_fnc_nearestRoad;

  private _agent = (createGroup east) createUnit [getText (_units_town select (random ((count _units_town) -1))), getPos _road1, [], 0, "NONE"];
  private _car = (getText (_vehicles_military select (random ((count _vehicles_military) -1)))) createVehicle (getPos _agent);
  _agent moveInDriver _car;

  private _pos2 = [_center, 5, _axis, 3, 0, 20, 0] call BIS_fnc_findSafePos;
  private _road2 = [_pos1, 500] call BIS_fnc_nearestRoad;

The Ai should move from _road1 to _road2.

 

Thanks for your help!

Share this post


Link to post
Share on other sites
12 hours ago, Smart Games said:

I managed to spawn them, but can't make them move. 

I tried calculatepath, setDestination, forcefollowroad and waypoints.


Just a hunch but _car is not moving because _pos1 is the same as _pos2, and _road1 is the same as _road2.

  • Like 3

Share this post


Link to post
Share on other sites
42 minutes ago, Maff said:


Just a hunch but _car is not moving because _pos1 is the same as _pos2, and _road1 is the same as _road2.

Oh God - I am so stupid. I forgot to make the second position a random one. 

Yeah, thank you! 😉

Share this post


Link to post
Share on other sites

just in case someone is looking for something similar.

 

spawning quad (near road) and driver - adding 2 random waypoints -  endless driving between both waypoints:

 

tested in initServer.sqf on Altis in Kavala:

waitUntil { sleep 1; time > 0 };

//center position of waypoint and spawn position search
private _center_pos = getPos saro_trigger;

// maximum distance between center and waypoints/vehicle spawn 
private _waypoint_search_radius = 500;

//minimum distance between both waypoints
private _wp_min_distance = 50;

//move player into vehicle (for testing)
_player_move_in = true;

//speed for moving ( "LIMITED" "NORMAL" "FULL" )
private _wp_speed = "FULL";

private ["_pos1", "_pos2", "_road1", "_road2", "_wp2"];

private _posvec = [0,0,8000];

private _wp_min_distanceSqr = _wp_min_distance^2;

while { (_posvec nearRoads 15) isEqualTo [] } do
{
 _posvec = [_center_pos, 0, _waypoint_search_radius, 7] call BIS_fnc_findSafePos;
};

//spawn hunter
_veh = createVehicle ["B_G_Quadbike_01_F", _posvec, [], 0, "NONE"];

//spawn unit and make driver
_unit = (createGroup west) createUnit ["B_crew_F", [0, 0, 8000] , [], 0, "CAN_COLLIDE"];
_unit assignAsDriver _veh;
_unit moveInDriver _veh;

if ( _player_move_in ) then { player moveInAny _veh; };

while { isNil "_road1" || isNil "_road2" || { _road1 distanceSqr _road2 < _wp_min_distanceSqr } } do
{
_pos1 = _center_pos getPos [ (random _waypoint_search_radius) , (random 360) ];
_pos2 = _center_pos getPos [ (random _waypoint_search_radius) , (random 360) ];

_road1 = (_pos1 nearRoads 50) select 0;
_road2 = (_pos2 nearRoads 50) select 0;
};

saro_wp1 = (group _unit) addWaypoint [(position _road1), 0];
_wp2 = (group _unit) addWaypoint [(position _road2), 0];

saro_wp1 setWaypointType "MOVE";
_wp2 setWaypointType "MOVE";

saro_wp1 setWaypointCompletionRadius 10;
_wp2 setWaypointCompletionRadius 10;

saro_wp1 setWaypointSpeed _wp_speed;
_wp2 setWaypointSpeed _wp_speed;

_wp2 setWaypointStatements ["true", "(saro_wp1 select 0) setCurrentWaypoint  saro_wp1;"];

 

  • Like 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

×