• Home
  • Portal
  • Forums
  • Search
  • Members
  • Log Out
  • Help
  • Extras
Forum stats
Show team
View New Posts
View Today's Posts

Comrades in Arms Discussion Board
Login to account Create an account
Login
Username:
Password: Lost Password?
 

  Comrades in Arms Discussion Board Comrades in Arms Life Mission Making
« Previous 1 2 3 4 5 ... 17 Next »
Locating the player's centre

Thread Modes
Locating the player's centre
Mjolnir Offline
CiA Member
*
Joined: Oct 2008
Posts: 321
#1
01-08-2021, 09:56 AM
Does anyone have, or know of a script that will locate the centre of mass of a group of players? I have an idea, but I need to be able to locate the centre point of a group of players to do it.
Lead me, Follow me, or Get out of my way.
Find
Reply
Varanon Online
CiA Member
*
Joined: Apr 2012
Posts: 1,816
#2
01-08-2021, 07:23 PM
I use this in our framework:

Code:
/* Find a circle [center, radius] enclosing all given units
* Note: This isn't the smalles circle around the units. Calculating the smallest
* circle is O(n²) and not really a necessity for us.
*
* The simple approach here is to find the lowest and highest x and y coordinates,
* and then form a circle enclosing that rectangle
*/

private _minX = (getPos (_this select 0)) select 0;
private _maxX = (getPos (_this select 0)) select 0;
private _minY =    (getPos (_this select 0)) select 1;
private _maxY = (getPos (_this select 0)) select 1;

{
   private _nx = (getPos _x) select 0;
   private _ny = (getPos _x) select 1;
   
   if (_nx < _minX) then {
       _minX = _nx;
   };
   
   if (_nx > _maxX) then {
       _maxX = _nx;
   };
   
   if (_ny < _minY) then {
       _minY = _ny;
   };
   
   if (_ny > _maxY) then {
       _maxY = _ny;
   };
} foreach _this;

private _center = [(_maxX + _minX)/2, (_maxY + _minY)/2, 0];
private _radius = [_maxX, _maxY, 0] distance _center;

[_center, _radius];


It's not optimal (i.e. the circle could still be tighter), but it works for, for example, spawning stuff outside the player's bubble
[Image: ju6KhLP.png][Image: sEBBGmA.png][Image: POVf9Kr.png]
Website Find
Reply
Variable Offline
CiA Member
*
Joined: Apr 2006
Posts: 6,948
#3
01-09-2021, 12:15 PM
Shouldn’t the title read players’ center?
The fewer men, the greater share of honor
[Image: 5552321289_7b6bf9a999.jpg]
Website Find
Reply
Mjolnir Offline
CiA Member
*
Joined: Oct 2008
Posts: 321
#4
01-23-2021, 10:06 PM
Varanon Wrote:I use this in our framework:

Code:
/* Find a circle [center, radius] enclosing all given units
* Note: This isn't the smalles circle around the units. Calculating the smallest
* circle is O(n²) and not really a necessity for us.
*
* The simple approach here is to find the lowest and highest x and y coordinates,
* and then form a circle enclosing that rectangle
*/

private _minX = (getPos (_this select 0)) select 0;
private _maxX = (getPos (_this select 0)) select 0;
private _minY =    (getPos (_this select 0)) select 1;
private _maxY = (getPos (_this select 0)) select 1;

{
   private _nx = (getPos _x) select 0;
   private _ny = (getPos _x) select 1;
   
   if (_nx < _minX) then {
       _minX = _nx;
   };
   
   if (_nx > _maxX) then {
       _maxX = _nx;
   };
   
   if (_ny < _minY) then {
       _minY = _ny;
   };
   
   if (_ny > _maxY) then {
       _maxY = _ny;
   };
} foreach _this;

private _center = [(_maxX + _minX)/2, (_maxY + _minY)/2, 0];
private _radius = [_maxX, _maxY, 0] distance _center;

[_center, _radius];


It's not optimal (i.e. the circle could still be tighter), but it works for, for example, spawning stuff outside the player's bubble

So I've come back to this, and you're going to have to explain how to use this to me like I'm 5 please, cause I dont know where to start
Lead me, Follow me, or Get out of my way.
Find
Reply
Varanon Online
CiA Member
*
Joined: Apr 2012
Posts: 1,816
#5
01-25-2021, 10:08 AM
Mjolnir Wrote:So I've come back to this, and you're going to have to explain how to use this to me like I'm 5 please, cause I dont know where to start

It finds the circle around the units, like this:

_circle = [unit1, unit2, unit3, uint4] call compile preprocessFileLineNumbers "script.sqf";

_circle select 0 is then the center point, and _circle select 1 is the radius. 

If you want all player units, you need to get them first:

Code:
_playable = (if (isMultiplayer) then {playableUnits} else {switchableUnits});
_players = [];
{
    if (side _x != sideLogic) then {
        _players pushBack _x;
    };
} forEach _playable;


_circle = _players call compile preprocessFIleLineNumbers "script.sqf";

hint format ["The players are in a circle at %1 with radius %2", _circle select 0, _circle select 1};

If you are using the FHQ framework, you can simply do

_circle = FHQ_PlayableUnits call FHQ_fnc_findBoundingCircle;
[Image: ju6KhLP.png][Image: sEBBGmA.png][Image: POVf9Kr.png]
Website Find
Reply


  • View a Printable Version
  • Subscribe to this thread

  • Contact Us
  • Forum team
  • Forum stats
  • Return to Top
 
  • RSS Syndication
  • Lite mode
  • Home
  • Help
 
Forum software by © MyBB - Theme © iAndrew 2014



Linear Mode
Threaded Mode