Luft08 27 Posted October 11, 2021 I went through the Global Mobilization map gathering the rough position data on bridges: eastGermanBridges = [ [10577.8,17680.2],[10889.8,17545.4],[12102.7,17199.6],[13399.5,15948],[14312.1,15123], [13630.1,12722.1],[14927.9,15361.6],[14943.2,15220.9],[15658.5,14663.3],[15663.2,14166.2], [16256.9,12515.4],[17365.1,11464.7],[18684.4,11083.3],[14927.8,15360.4],[16192.9,15358], [18230.3,15977.5],[19959.8,4850.35],[18082.2,5211.08],[16399.4,6661.06],[16143.3,6951.2], [15553.2,8796.89],[14255.2,11924.2],[13137.8,8403.86],[12917.6,8265.83],[12582.7,7924.79], [13666.6,4606.77],[13870.7,4370.2],[15269.4,2432.02],[16340.1,178.734] ]; I wrote a function that takes a position and is suppose to return true if that position is at a bridge. However, it always returns false. isOnBridge: params["_pos"]; if((count _pos) == 2) then { _pos pushBack 0}; private _result = false; if(isOnRoad _pos) then { private _nearestRoad = [_pos, 10] call BIS_fnc_nearestRoad; private _roadInfo = getRoadInfo _nearestRoad; _result = (_roadInfo select 8); }; _result I was using bridge position data I gathered by hand so I figured that it wasn’t accurate enough so I wrote a function that takes the rough data and returns more precise data: private _bridgeSeg = []; { private _nearPos = _x; private _roadSegs = _nearPos nearRoads 50; { private _roadInfo = getRoadInfo _x; private _isBridge = _roadInfo select 8; if(_isBridge) then { _bridgeSeg pushBack (getPos _x); }; } forEach _roadSegs; } forEach eastGermanBridges; diag_log format ["Bridge Array = %1", _bridgeSeg]; The updated data: eastGermanBridges = [ [10578.4,17680.9,12.4872],[10889.6,17544.5,12.8538],[12102.4,17199.3,12.5763], [13400.2,15949.4,12.8326],[14315,15122.7,12.4278],[13628.6,12721.3,12.5986], [14928.2,15360,12.1543],[14943.7,15219.7,12.9992],[15660.1,14663.1,13.0124], [15664.2,14165.7,14.3585],[16255.7,12514.4,13.1765],[17356.8,11455.1,14.3627], [17371.4,11468.7,16.0603],[17386,11482.4,12.3864],[18685.7,11083.8,14.1605], [14928.2,15360,12.1543],[16193.1,15347.6,14.5347],[16193.4,15367.6,15.7658], [18223.9,15987.5,15.8225],[18235.9,15971.4,16.2582],[19959.6,4850.25,16.6743], [18082.3,5211.1,14.82],[16399.5,6661.06,12.4695],[16143.4,6951.2,14.6601], [16156.9,6965.9,13.1921],[15543.3,8794.17,14.8643],[15562.5,8799.49,14.7014], [14255.7,11925.7,14.6887],[13138.5,8405,14.5256],[12920,8264.23,14.1931], [12581.9,7926.16,12.985],[13667,4607.53,11.6135],[13869.8,4369.87,15.0714], [15269.2,2432,14.7458],[16338.1,177.258,16.1915] ]; When I tested the function again it still returns false even when I pass the exact bridge position. Share this post Link to post Share on other sites
pierremgi 4737 Posted October 12, 2021 Don't triple (even double) post! https://forums.bohemia.net/forums/topic/235999-task-not-completing/?tab=comments#comment-3446788 https://forums.bohemia.net/forums/topic/235994-how-do-you-prevent-a-randomly-spawned-vehicle-from-spawning-on-a-bridge/?tab=comments#comment-3446752 Share this post Link to post Share on other sites
Luft08 27 Posted October 12, 2021 2 hours ago, pierremgi said: Don't triple (even double) post! https://forums.bohemia.net/forums/topic/235999-task-not-completing/?tab=comments#comment-3446788 https://forums.bohemia.net/forums/topic/235994-how-do-you-prevent-a-randomly-spawned-vehicle-from-spawning-on-a-bridge/?tab=comments#comment-3446752 Sorry. Although the threads deal with similar issues aimed at solving problems in the same mission they ARE different. The first deals with a variable holding a bridge object. Only it didn't because it was being loaded with objects near the bridge. That issue was solved. You do have a point about the second thread and this thread. They are similar enough that perhaps I should have just reopened the second thread and tacked on the additional information but being that I wrote code that looks like it should work but doesn't, it seemed to me to be a different issue. In retrospect it may have been too close to an earlier post. I do apologize for the similar posts but still don't know why the code I posted fails. Share this post Link to post Share on other sites
Ibragim A 148 Posted October 12, 2021 I don't know why, but not all maps can define roads using the nearRoads command. On some maps, this command does not find anything. Therefore, it would be good to additionally search for roads with the nearestTerrainObjects: _nearest_road_pos = []; _roads1 = nearestTerrainObjects [_position, ["Road"], 50]; // nearest _roads2 = _position nearRoads 50; // not nearest _roads = _roads1 + _roads2; // find nearest: if (count _roads > 0) then { _roads = _roads apply { [_x distance (_position), _x] }; _roads sort true; _nearest_road_pos = position (_roads select 0 select 1); }; Also, it seems that isOnBridge will always return false because it uses isOnRoad, which requires z coordinates in AGL or 2D format. if((count _pos) == 2) then { _pos pushBack 0}; // <-- delete it if((count _pos) > 2) then { _pos = [_pos select 0, _pos select 1]}; // try it Share this post Link to post Share on other sites
Luft08 27 Posted October 14, 2021 On 10/11/2021 at 8:39 PM, Ibragim A said: I don't know why, but not all maps can define roads using the nearRoads command. On some maps, this command does not find anything. Therefore, it would be good to additionally search for roads with the nearestTerrainObjects: _nearest_road_pos = []; _roads1 = nearestTerrainObjects [_position, ["Road"], 50]; // nearest _roads2 = _position nearRoads 50; // not nearest _roads = _roads1 + _roads2; // find nearest: if (count _roads > 0) then { _roads = _roads apply { [_x distance (_position), _x] }; _roads sort true; _nearest_road_pos = position (_roads select 0 select 1); }; Also, it seems that isOnBridge will always return false because it uses isOnRoad, which requires z coordinates in AGL or 2D format. if((count _pos) == 2) then { _pos pushBack 0}; // <-- delete it if((count _pos) > 2) then { _pos = [_pos select 0, _pos select 1]}; // try it Thanks, I ended up using: params["_pos"]; private _result = false; private _pos2D = [_pos select 0, _pos select 1]; private _nearestRoad = [_pos2D, 5] call BIS_fnc_nearestRoad; if (!(_nearestRoad isEqualTo objNull)) then { private _roadInfo = getRoadInfo _nearestRoad; _result = (_roadInfo select 8); }; _result It doesn't tell me if the EXACT position is a bridge but does tell me if the nearest road within 5m of the specified position is a bridge. Close enough, I think. Share this post Link to post Share on other sites
Ibragim A 148 Posted October 14, 2021 BIS_fnc_nearestRoad does not return position, function returns road object. Therefore, you just need to get the position of this _nearestRoad. _result = [false, objNull]; //... _bridgePos = position _nearestRoad; _result = [(_roadInfo select 8), _bridgePos]; You will get return value of true and bridge position. Share this post Link to post Share on other sites