Jump to content
Sign in to follow this  
ColonelSandersLite

Small gift

Recommended Posts

As much to celebrate my return as anything else, I though I'd post here a small function I wrote. Enjoy!

getHorizontalDistanceCSL.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

// Why not just use obj1 distance obj2 from the comref?

// The function built into the game engine gets true distance only.

// This function should be used when you have a need to get the distance from

// point A to point B as a pure horizontal distance (like on a map)

// in some situations this can make a world of difference.

// especially when you're dealing with flying objects.

//

// example (assumes above sea level for the altitudes, even though in game they arent):

// suppose that you have 2 aircraft AircraftA and AircraftB

// aircraftA's position is [1000.00,1000.00,50.00]

// aircraftB's position is [1500.00,1000.00,550.00]

// AircraftA's True Distance from Aircraft B is 707.106 meters

// AircraftA's horizontal (map) Distance from Aircraft B is only 500 meters though

//

// this is actually the reason the ofp ai can't hit a waypoint if it's flying over a certain altitude

// if it's flying high enough, it can't get within range to trigger it as the ofp engine does true distance

// using this function, you can get certain things to work a LOT better

//

//

// to get this function to work:

//

// copy and paste this code into a file called getHorizontalDistanceCSL.sqf

//

// in init.sqs, preprocess this function as so:

// getHorizontalDistanceCSL = preprocessFile "getHorizontalDistanceCSL.sqf"

//

// then use it in any script or tirgger like so:

// myvariable = [positionA, postionB] call getHorizontalDistanceCSL

//

// This function will always return a positive or zero decimal distance

//

// example to get the horizontal distance between 2 helicopters

// _x = [getPos _myHeli1, getPos _myHeli2] call getHorizontalDistanceCSL

//

// example to get the horizontal distance between an aircraft and a marker position

// _x = [getPos _myAircraft, getMarkerPos "MyMarker"] call getHorizontalDistanceCSL

//

// example to get the horizontal distance between a helicopter and a soldier

// _x = [getPos _myHeli, getPos _mySoldier] call getHorizontalDistanceCSL

//

// example to get the horizontal distance between 2 hardcoded positions

// _x = [[1234.56, 1234.56, 1234.56], [6543.21, 6543.21, 6543.21]] call getHorizontalDistanceCSL

//

// example to get the horizontal distance between 2 variables holding positions

// _x = [_myPosA, _myPosB] call getHorizontalDistanceCSL

//

// it's funny that the comments are longer than the actual script...

//

// If you can read this you don't need glasses....

private ["_positionACSL", "_positionBCSL", "_distanceACSL", "_distanceBCSL", "_distanceCCSL", "_output"];

_postionACSL = _this select 0;

_postionBCSL = _this select 1;

_distanceACSL = (_postionACSL select 0) - (_postionBCSL select 0);

_distanceBCSL = (_postionACSL select 1) - (_postionBCSL select 1);

_distanceCCSL = sqrt ((_distanceACSL * _distanceACSL) + (_distanceBCSL * _distanceBCSL));

_output = _distanceCCSL;

_output

Share this post


Link to post
Share on other sites

arghhh - sorry - i didn't read the first line of your

code forget my post if you've read it already biggrin_o.gif

Nice work Col smile_o.gif

You know we have that function library at OFPEC

if you didn't already put it there ...

~S~ CD

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
Sign in to follow this  

×