Home   Help Search Login Register  

Author Topic: Problem with a mobile spawn idea  (Read 2106 times)

0 Members and 1 Guest are viewing this topic.

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Problem with a mobile spawn idea
« on: 11 Feb 2009, 18:11:04 »
I've got a strange question, but I'm hoping someone can help!

I've made a small script to spawn team members just behind the squad leader, based on the direction he's facing... but I've got a problem: sometimes, team members spawn on/in objects if the squad leader has his back to an object, or is inside a building, etc.

Is there any easy way to check that the spawn point is not placed on top of any object, or within an object (e.g. within the area of a building), and move it to the 'nearest' position to the squad leader, that is 'open'?

To be more specific, I'm looking for a way to determine if a particular position [x,y] intersects with a boundingBox for any nearby object (so that I can then work out at what position near [x,y] there is no intersection with any boundingBox).

I've searched high and low, and not really come up with anything.

Thanks in advance.
« Last Edit: 11 Feb 2009, 19:23:00 by JamesF1 »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Problem with a mobile spawn idea
« Reply #1 on: 11 Feb 2009, 18:24:27 »
You may use nearestObjects using "House" as class filter and a short radious (5 or 6m), and if a house it detected then do ... ...what?

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Problem with a mobile spawn idea
« Reply #2 on: 11 Feb 2009, 18:28:53 »
Yeah, I thought about that, and that works fine for locating the building... but the problem is more related to then finding if the current marker location for the spawn point intersects with the building itself, and if so, finding a location (in the open) as close to the 'ideal' location as possible, to place the marker.

Sorry if I wasn't clear enough the first time around!

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Problem with a mobile spawn idea
« Reply #3 on: 11 Feb 2009, 19:22:59 »
You could use boundingBox to check if the spawn point intersects with the house.
try { return true; } finally { return false; }

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Problem with a mobile spawn idea
« Reply #4 on: 11 Feb 2009, 19:31:12 »
I've been looking into that, but I'm not really sure where to start.  I've done some simple bounds checking, but it doesn't really seem to be achieving what I want it to a achieve.  Would you, or someone else, mind giving an example, please?  :)

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Problem with a mobile spawn idea
« Reply #5 on: 11 Feb 2009, 19:52:35 »
Hmmm, worldToModel is also required.
try { return true; } finally { return false; }

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Problem with a mobile spawn idea
« Reply #6 on: 11 Feb 2009, 19:57:44 »
Whilst I'm still very interested in if/how this can be reliably implemented in ArmA... I've opted for a different route in this particular mission for the time being... I had some of the above suggestions going to find intersecting objects, but it was just a bit too laggy for it to be effective... maybe I'm doing something dreadfully wrong (getting nearest objects to the squad leader, and attempting to find if any of them intersect with the proposed spawn location)?

Thanks for all the suggestions thus far :)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Problem with a mobile spawn idea
« Reply #7 on: 11 Feb 2009, 19:59:34 »
Function I wrote ages ago:
overObj.sqf
Code: [Select]
private ["_pos","_dist","_type","_buf","_breakflag","_objs","_obj","_j","_c","_xmin","_xmax","_ymin","_ymax","_zmin","_zmax","_mpos","_mx","_my","_mz","_wz","_return"];
_pos = _this select 0;
_type = _this select 1;
_dist = _this select 2;
_buf = [0,0,0];
if (count _this > 3) then {_buf = _this select 3;};
_breakflag = TRUE;  
_objs = nearestObjects [_pos, _type, _dist];

for [{_j = 0},{_j < count _objs && _breakflag},{_j = _j + 1}] do
{
   _obj = _objs select _j;
   _c = boundingBox _obj;
   _xmin = ((_c select 0) select 0) - (_buf select 0);
   _xmax = ((_c select 1) select 0) + (_buf select 0);
   _ymin = ((_c select 0) select 1) - (_buf select 1);
   _ymax = ((_c select 1) select 1) + (_buf select 1);
   _zmin = ((_c select 0) select 2) - (_buf select 2);
   _zmax = ((_c select 1) select 2) + (_buf select 2);
   _mpos = _obj worldToModel _pos;
   _mx = _mpos select 0;
   _my = _mpos select 1;
   _mz = _mpos select 2;
   if (_mx > _xmin && _mx < _xmax && _my > _ymin && _my < _ymax) then
   {
      _breakflag = FALSE;
      _wz = (_obj modelToWorld [0,0,_zmax]) select 2;
   };
};
[not _breakflag, _wz, if _breakflag then {objNull} else {_obj}]

Initialize it somewhere, maybe init.sqf
Code: [Select]
overObj = compile preProcessFileLineNumbers "overobj.sqf";
Call it like so:
Code: [Select]
_return = [_pos, _type, _dist] call overObj;where _pos is a 3D position, so if you are using a marker you must add a 0 for height, _type is the object class you want to test against, in your case "All", and _dist is how far away you want to search. _dist should be set to something like 50.

Code: [Select]
_return select 0;True if inside object, False othewise
Code: [Select]
_return select 1;Height above object. You don't need this.
Code: [Select]
_return select 0;Intersecting object position is inside. Will be objNull if _return select 0 is False.

All commands that search for objects are laggy, so you do not want to run them constantly. What you need to do is call the function only when a player dies, making sure the respawn delay is set high enough.
« Last Edit: 11 Feb 2009, 20:03:55 by Mr.Peanut »
urp!

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Problem with a mobile spawn idea
« Reply #8 on: 11 Feb 2009, 20:23:33 »
I came up with this one:

Code: (isWithin.sqf) [Select]
/* Check if a position is within an object.
 *
 * SYNTAX:      [Object, Position] execVM "isWithin.sqf";
 * RETURNS:     True or False
 */

private ["_obj","_orgPos","_pos","_box","_min","_max","_within"];

_obj    = _this select 0;
_orgPos = _this select 1;

_pos = _obj worldToModel _orgPos;

_box = boundingBox _obj;
_min = _box select 0;
_max = _box select 1;

_within = ((_min select 0 < _pos select 0) and (_pos select 0 < _max select 0)) and
          ((_min select 1 < _pos select 1) and (_pos select 1 < _max select 1)) and
          ((_min select 2 < _pos select 2) and (_pos select 2 < _max select 2));

_within; // return value


Example:

Code: [Select]
isFree = [jail1, getPos grunt1] execVM "isWithin.sqf";
hint str(isFree);
try { return true; } finally { return false; }

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Problem with a mobile spawn idea
« Reply #9 on: 11 Feb 2009, 20:36:19 »
Beware of bounding boxes, they consider even tall antennas, etc.

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Problem with a mobile spawn idea
« Reply #10 on: 11 Feb 2009, 20:58:14 »
Good point! There are also problems with some buildings. For example, the red space on the picture below is within the bounding box of the house. So a unit positioned there will be reported as "inside" by my function.

There seems to be no sane way to get around this limitation.
« Last Edit: 11 Feb 2009, 21:00:26 by Worldeater »
try { return true; } finally { return false; }

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Problem with a mobile spawn idea
« Reply #11 on: 12 Feb 2009, 01:13:03 »
Thanks for the samples and ideas, guys... I'll take a look into it tomorrow, when I'm not about to fall asleep at the keyboard!

Edit: I'm not overly concerned about the bounding box not always being the edge of the building, it's just more so I don't spawn people in obviously bad positions... :)
« Last Edit: 12 Feb 2009, 01:15:52 by JamesF1 »