ghandolhagen 11 Posted February 28, 2016 Hello I am attempting to have one vehicle follow a lead vehicle's current position whenever the distance between them is greater than 10 metres. Here is my first stab which doesn't work. The second vehicle does move to where the first vehicle WAS but then stops. It is as if the code is not updating the current position of the lead vehicle. Any ideas? Cheers! while{alive VIC1}do{currPos = getPos VIC1;}; dist = VIC2 distance VIC1 > 10; while{dist}do{VIC2 doMove currPos; VIC2 setSpeedMode "LIMITED";}; Share this post Link to post Share on other sites
nikiller 18 Posted February 28, 2016 hi, Try this (not tested): //[vehicleName, followerName, delay] execVM "scriptName.sqf" //By Nikiller //28/02/2016 _vehicle = _this select 0; _follower = _this select 1; _delay = _this select 2; while {(canMove _vehicle) && (canMove _follower)} do { _pos = getPos _vehicle; _distance = _follower distance _vehicle; if (_distance > 10) then { _follower doMove _pos; _follower setSpeedMode "LIMITED"; }; sleep _delay; }; cya. Nikiller. 1 Share this post Link to post Share on other sites
inlesco 233 Posted February 28, 2016 Currently there's no viable solution to keep convoy formation (vehicle keeping X meters inbetween). Setting waypoints to the lead vehicle's position is in no way efficient or reliable. I'm afraid we'll have to wait for improvements from BIS on this end. 2 Share this post Link to post Share on other sites
ghandolhagen 11 Posted February 28, 2016 Thanks everyone for the responses! nikiller, I have not encountered canMove before, so thanks for the education! :D One other thing. I have seen this select 0 before, but what does it refer to? That concept is fuzzy for me. Share this post Link to post Share on other sites
jshock 513 Posted February 28, 2016 I have seen this select 0 before, but what does it refer to? That concept is fuzzy for me. https://community.bistudio.com/wiki/Array 1 Share this post Link to post Share on other sites
nikiller 18 Posted February 28, 2016 Thanks everyone for the responses! nikiller, I have not encountered canMove before, so thanks for the education! :D One other thing. I have seen this select 0 before, but what does it refer to? That concept is fuzzy for me. No problem, but as Inlesco said it is not very reliable and I am not sure it will work well. Your best bet is to wait for BIS convoy fix. 1 Share this post Link to post Share on other sites
haleks 8212 Posted February 28, 2016 One thing I have noticed : I have been trying to make a convoy mission for a long, long time... If the lead vehicle is driven by the player - or if the player is the leader of the convoy, things will go to hell pretty quickly... But if you let an AI leader handle everything, set up the proper formation etc..., NPCs will usually have an easier time maintaining formation. 1 Share this post Link to post Share on other sites
ghandolhagen 11 Posted February 28, 2016 jshock, Oh so it is just an index in an array. So does the script in Arma treat every variable as an array? Share this post Link to post Share on other sites
jshock 513 Posted February 28, 2016 It treats every array variable as an array, not every variable. Share this post Link to post Share on other sites
ghandolhagen 11 Posted February 28, 2016 Just wanted to update. I modified my script a bit and I got a solution that seems to work mostly. I give the following vehicle it's own series of waypoints but at each waypoint activation I run this and what seems to happen is that it recalculates the lead vehicles position at each waypoint. There is a slight stop or slow down of the following vehicle at each way point, but I think i can live with that. :D : VIC2 disableAi "Move"; while{alive VIC1}do{currPos = getPos VIC1;}; dist = VIC2 distance VIC1 > 10; while{dist}do{ VIC2 enableAi "MOVE"; VIC2 doMove currPos; VIC2 setSpeedMode "LIMITED";}; Share this post Link to post Share on other sites
ghandolhagen 11 Posted February 29, 2016 Further Update. I removed the follower vehicle's way points and instead assigned the lead vehicle the waypoints. Then in each of those onAct I just update the currPos with a getPos on the lead vic and then also tell the follower vic to move to currPos. By spacing out the waypoints and playing with the speed of the lead vehicle, the following vehicle can move along at a good clip as it is always playing catch up with the lead. Not perfect but it is serviceable. Thanks everyone for the assistance. This community is awesome! A note: two vehicles works pretty good, three or more and it gets dicey. Share this post Link to post Share on other sites
dreadedentity 278 Posted February 29, 2016 jshock, Oh so it is just an index in an array. So does the script in Arma treat every variable as an array? Arugments are passed to code and (usually) saved to _this variable. There are special cases. Using select allows you to take a specific parameter from the passed array. Share this post Link to post Share on other sites