ADuke 1 Posted January 13, 2012 Hi, So, what I am trying to do is place scripted waypoints along 2 points, who's positions can change at any time. Here is an image illustrating what I would like to do.. So, points A and B can be anywhere, but I would like the waypoints to ALWAYS be placed along the line from the 2 points, I know how to script waypoints, and how to place those waypoints at a position like this... _wppos1 = [getpos _object select 0, (getpos _object select 1)+60, getpos _object select 2]; _wp1 = _group1 addWaypoint [_wppos1,1]; [_group1, 1] setWaypointType "MOVE"; [_group1, 1] setWaypointSpeed "LIMITED"; [_group1, 1] setWaypointBehaviour "SAFE"; The part I am having trouble with is creating the waypoints along a straight line between the 2 points, no matter where the points are. Your help is appreciated, -AD Share this post Link to post Share on other sites
shuko 59 Posted January 13, 2012 Are they supposed to be like in the picture, unevenly distributed? If so, what are the distance ratios? Share this post Link to post Share on other sites
twirly 11 Posted January 13, 2012 (edited) Knocked this up quickly for you.... and tested it. Test mission here. call with:- nul = ["mkr_1","mkr_2",100] execVM "test.sqf"; where... "mkr_1" and "mkr_2" are your markers... and 100 is the distance from the first marker along the azimuth to the second marker. test.sqf:- _mkr1 = _this select 0; _mkr2 = _this select 1; _deltadis = _this select 2; _x1 = (getMarkerPos _mkr1) select 0; _y1 = (getMarkerPos _mkr1) select 1; _x2 = (getMarkerPos _mkr2) select 0; _y2 = (getMarkerPos _mkr2) select 1; //get deltas _dx = _x2 - _x1; _dy = _y2 - _y1; //get angle between markers _ang = _dx atan2 _dy; //fix angle if <0 or >360 _ang = _ang mod 360; //find new coords _newx = _x1 + sin(_ang)*_deltadis; _newy = _y1 + cos(_ang)*_deltadis; _newcoords = [_newx,_newy,0]; hint format ["newcoords: %1",_newcoords]; //draw a marker here _mkr = format ["mkr_%1", diag_ticktime]; //give it a unique name _m = createMarkerLocal [_mkr, _newcoords]; _m setMarkerShapeLocal "ELLIPSE"; _m setMarkerSizeLocal [20,20]; _m setMarkerColorLocal "colorRED"; _m setMarkerDirLocal 0; If you choose a distance in the call that is more than the distance between the markers.... a projection along the calculated azimuth will be done. This point will lie outside of the line between the two markers. This may not be an ideal solution for you....but shows you the math. The distance should really be a percentage of the whole I guess.... but this will get you on your way. If you have trouble with it... I'll be glad to help. Edited January 13, 2012 by twirly Clarity Share this post Link to post Share on other sites
shuko 59 Posted January 13, 2012 Going to bed, but here's one with even distance between WPs. Parameters: [pos1,pos2,waypoint count] waituntil {BIS_fnc_init}; private ["_posA","_posB","_cnt","_dst","_dir","_pos","_d","_p"]; _posA = _this select 0; _posB = _this select 1; if (typename _posA == "OBJECT") then {_posA = getpos _posA}; if (typename _posB == "OBJECT") then {_posB = getpos _posB}; _cnt = _this select 2; _dst = _posA distance _posB; _dst = _dst / (_cnt + 1); _dir = [_posA,_posB] call BIS_fnc_dirTo; _pos = []; for "_i" from 0 to (_cnt - 1) do { _d = _dst * (_i + 1); _p = [_posA,_d,_dir] call BIS_fnc_relPos; _pos set [_i,_p]; }; Share this post Link to post Share on other sites
ADuke 1 Posted January 14, 2012 Thanks a lot guys, that sounds like exactly what I am looking for, going to give it a try once I take care of some other roadblocks and will definitely post the results. Thanks again, -AD Share this post Link to post Share on other sites
rübe 127 Posted January 14, 2012 Hi, who's positions can change at any time. If that's the key part, then I suggest a "lazy" variant, that calculates the next waypoint as needed (at some distance in the direction of your goal, maybe randomized if the distance is still great) instead of calculating them all in once. Have you ever heard of Zeno's turtle? :D This way you could also factor in stuff like the player's direction on reaching a waypoint, etc. Share this post Link to post Share on other sites
ADuke 1 Posted January 14, 2012 (edited) If that's the key part, then I suggest a "lazy" variant, that calculates the next waypoint as needed (at some distance in the direction of your goal, maybe randomized if the distance is still great) instead of calculating them all in once. Have you ever heard of Zeno's turtle? :DThis way you could also factor in stuff like the player's direction on reaching a waypoint, etc. I think I know what you are getting at, and I have done just that..... I decided to go the functions route since I spawn that module early on in this script. Between the creation of each waypoint I define the direction and the relative position of my variable "_wppos". _dir = [_spawnpos,_destpos] call BIS_fnc_dirTo; _wppos = [_spawnpos,100,_dir] call BIS_fnc_relPos; Each waypoint is then created at (the newly defined) "_wppos" The first two waypoints are in front of Point A or "_spawnpos" (facing in the direction of Point B or "_destpos") at 100 meter intervals. The last two are in front of Point B (facing in the direction of Point A) at 100 meter intervals, until the trip is complete. Overlapping of waypoints here is virtually impossible since the distance of Point A to Point B usually averages 1000 meters. I have not completed the script yet (lots of distractions today) but when I finish it I will post the results. Thanks for everyone's help and expertise. -AD P.S. Is it meters or kilometers? not sure since we use the imperial method here of course. Edited January 14, 2012 by ADuke Share this post Link to post Share on other sites
rübe 127 Posted January 14, 2012 that would be meters. ;) Share this post Link to post Share on other sites