RazorX 10 Posted January 4, 2011 (edited) is there a good script for following. I want a unit to follow another unit (like in a group formation) but I want both units to be in separate teams. Any ideas? I'm currently using something simple including this: _unit domove (_target modelToWorld [0,-8,0]); sleep 3; in a loop the example above was created for vehicles Edited January 4, 2011 by RazorX Share this post Link to post Share on other sites
demonized 20 Posted January 5, 2011 _follower = _this select 0; // unit wich is doing following. _leader = _this select 1; // unit wich is being followed. _range = 25; //range to follow at. _combatBeheaviour = "AWARE"; // this is used for moving. _followerGrp = group _follower; // get group of follower. _leadGrp = group _leader; // get group of leader. _stillMoving = true; // set a variable we can use. // create a waypoint. _wp = _followerGrp addWaypoint [getPos (leader _ leadGrp), 0]; _wp setWaypointType "MOVE"; _wp setWaypointBehaviour _combatBeheaviour; _wp setWaypointSpeed "FULL"; while {_stillMoving} do { _follower = leader _followerGrp ; // get leader follower group. _leader = leader _leadrGrp ; // get leader lead group. // if follower and leader is alive and distance follower and leader is less than _range - move wp to follower pos (stop). if (alive _leader AND alive _follower AND _follower distance (getPos _leader) > _range) then { _wp setWPPos getPos _follower; // move wp to leader follow group position. sleep 0.01; _follower doMove getWPPos _wp; // order leader to move to his wp - should force leader to regroup his men on himself. }; sleep 2; // if follower and leader is alive and distance follower and leader is more than _range + 10 move wp to leader pos. (continue). if (alive _leader AND alive _follower AND _follower distance (getPos _leader) < (_range + 10)) then { _wp setWPPos getPos _leader; }; sleep 2; // if either of the two groups have 0 units in them, exit script. if (count _followerGrp == 0 OR count _leadGrp == 0) then { _stillMoving = false; hint "all is dead exiting script"; }; }; // END Not tested but think it should work, maybe you need one more doMove command in there after reaching distance set. Also could probably be done easier, but this is my level of coding, still leaarning so a bit primitiv perhaps :) Share this post Link to post Share on other sites
RazorX 10 Posted January 5, 2011 (edited) Analysing your code here, I see, you are using waypoints to make one group follow another group. But I want a single unit from one group to follow a single unit from another group (groups with no formation, because units in my groups don't move in formation) or a unit from the same group following another one from the same group (and not using AssignTeam). That's a bit of problematic code to invent especially when scripted for following vehicles Edited January 5, 2011 by RazorX Share this post Link to post Share on other sites
MeIvin 10 Posted January 5, 2011 Hello, is this what you're looking for? http://forums.bistudio.com/showthread.php?t=97339&highlight=follow Hope it helps. Kind regards Melvin Share this post Link to post Share on other sites
Big Dawg KS 6 Posted January 5, 2011 is there a good script for following. I want a unit to follow another unit (like in a group formation) but I want both units to be in separate teams. Any ideas?I'm currently using something simple including this: _unit domove (_target modelToWorld [0,-8,0]); sleep 3; in a loop the example above was created for vehicles So does this not work? Share this post Link to post Share on other sites
RazorX 10 Posted January 5, 2011 yes, it works. But try it on vehicles. Works not to well. On normal units works good Share this post Link to post Share on other sites
demonized 20 Posted January 5, 2011 If you want 1 unit from group one to follow 1 unit from group 2, then i think you are stuck with doMove. Why do you need follower to be in its previous group while following, cant you just let follower join his own group then whenever the reason you had for him to be in his old group occurs just rejoin??? My script works if you unjoin him as well, a single unit is leader in his own group. Share this post Link to post Share on other sites
RazorX 10 Posted January 5, 2011 That's because I don't want about 800 units to be in their own groups because I just can't do it with 144 group limit. I have most units joined 1 group. The player is in a separate group. I want a solution to one of the AI follow player or one of the members of his own group. That's the tricky point Share this post Link to post Share on other sites
Big Dawg KS 6 Posted January 6, 2011 Well, doMove seems like the most logical way, though you could give moveTo a shot; apparently it's a lower level move command so it may override some AI FSM behavior. Share this post Link to post Share on other sites
RazorX 10 Posted January 6, 2011 (edited) Well, doMove seems like the most logical way, though you could give moveTo a shot; apparently it's a lower level move command so it may override some AI FSM behavior. I think domove is best. Works great on units, but when used on vehicles, the driver slows down after doMove is issued to calculate new route to the target. With 3- or 2-second sleep it means, the driver slows down pretty often, so that's the first bug when used on drivers of vehicles. The first vehicles drives normally but the one that follows it drives a bit too slow to catch up to it. And I can't extend the sleep time because the results will be worse. EDIT _unit = _this select 0; //must be a unit, not a vehicle _target = _this select 1; //must be a vehicle scopeName "notFollow"; for "_a" from 0 to 1 step 0 do { _unit domove (_target modelToWorld [0,-5,0]); waituntil {unitReady _unit}; //prevent crashing into the car that is being followed when not moving if ((position _unit distance position _target) < 12) then { vehicle _unit setvelocity [0,0,0]; } else { //stop following while the unit is too far away if ((position _unit distance position _target) > 1000) then { breakTo "notFollow"; }; }; }; New script written, works almost perfectly ;) Edited January 8, 2011 by RazorX Share this post Link to post Share on other sites
Monan101 10 Posted June 23, 2011 i've found a more simple solution to this problem, i had a similar problem it goes. b domove (a modelToWorld [7]); "b" being the unit you want to follow another unit. "a" being the unit to be followed. works for me so far. make sure to name each unit Share this post Link to post Share on other sites
kylania 568 Posted June 23, 2011 Just attachTo b to a for the lulz. :) Share this post Link to post Share on other sites
madmonkey119 13 Posted October 21, 2016 Fixed the bugs in the script earlier as I thought it was quite useful _follower = _this select 0; // unit wich is doing following. _leader = _this select 1; // unit wich is being followed. _range = _this select 2; //range to follow at. _combatBeheaviour = "AWARE"; // this is used for moving. _followerGrp = group _follower; // get group of follower. _leadGrp = group _leader; // get group of leader. _stillMoving = true; // set a variable we can use. // create a waypoint. _wp = _followerGrp addWaypoint [getPos (leader _leadGrp), 0]; _wp setWaypointType "MOVE"; _wp setWaypointBehaviour _combatBeheaviour; _wp setWaypointSpeed "FULL"; while {_stillMoving} do { _follower = leader _followerGrp ; // get leader follower group. _leader = leader _leadGrp ; // get leader lead group. if (alive _leader AND alive _follower AND _follower distance (getPos _leader) > _range) then { _wp setWPPos getPos _leader; sleep 0.01; _follower doMove getWPPos _wp; }; sleep 2; if (count units _followerGrp == 0 OR count units _leadGrp == 0) then { _stillMoving = false; hint "all is dead exiting script"; }; }; // END Share this post Link to post Share on other sites