Warning: include(/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php): failed to open stream: No such file or directory in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Warning: include(): Failed opening '/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php' for inclusion (include_path='.:/usr/local/lib/php') in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Notice: Undefined index: OFPEC in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152
    Home   Help Login Register  

Author Topic: How to check if a unit is inside a building (i.e 2nd floor)  (Read 3517 times)

0 Members and 1 Guest are viewing this topic.

Offline Nikiller

  • Nogova Most Wanted
  • Members
  • *
  • ofp scripting addict
    • [LOL] ArmA ofp Site
hi,

Anyone know if there's a reliable way to check if a unit is inside a building?

I want to do that because I want that AI move to enemy position when he is inside a building. It works with houses but not buildings with floors. Most of time when enemy is at i.e second floor AI will stuck in front of the building and will do nothing. I have a solution to move AI inside building but I need the condition to check if the enemy is inside a building.

I tried different stuffs:

- Check the distance between the unit and the nearest building if (_unit distance (nearestBuilding _unit)<_distance) then {hint "in"} else {hint "out"} but it is not reliable since it checks the building model center and every building have a different one.

- Check the unit height if (!(_unit==vehicle) && (_unit select 2>1)) then {hint "in"} else {hint "out"} but it doesn't work because height doesn't change when you are in a building even if you are at the second floor.

- I placed gamelogic to the nearest building predefined positions and check the distance between unit and gamelogic but it's not reliable and not really an option since it will make too much gamelogic.

- I put all building with floor ID in array and check the distance between unit and element but I would to make the script works on any island then it's not an option.

ModelToWorld command is badly needed in ofp :(

Any help?

cya.

Nikiller.

Offline Gruntage

  • Missions Depot
  • Administrator
  • *****
  • How do I get outta this chickensh*t outfit?
Re: How to check if a unit is inside a building (i.e 2nd floor)
« Reply #1 on: 20 Sep 2012, 11:54:41 »
Interesting. Alright, first of all, please could you remove your signature? Images (both animated and inanimated) are not permitted as signatures here.

In regards to your question, couldn't you just place rectangular triggers on top of enterable buildings?

How many buildings roughly are we talking about here? Are we dealing with small urban combat situations? AI are particularly bad when it comes to CQB; they can walk through walls, see through walls, and even shoot through walls.

If we're talking about a small selection of buildings, then the placing of triggers shouldn't be too much hassle.

-Put a rectangular trigger on top of an enterable building, and size it accordingly.
-Group the trigger to a unit (the unit you want to check when inside a building)
-Make another unit (the unit to move to the building's location, or the trigger's location in this instance)
-In the trigger we placed earlier, put this in the On activation field:

Code: [Select]
loon1 move (getpos trig1)
loon1 is the response unit, trig1 is the name of the trigger on top of the building

You'll need to make quite a few triggers if you go with this solution. You could still use a gamelogic, by setpos'ing it to the location of the building trigger, and finding the nearestbuilding to the gamelogic. I'm not sure whether nearestbuilding works with triggers. Once the gamelogic has found the nearestbuilding, you can then find out the number of buildingpos in that building, and move a unit to each position in turn.

This would simulate a unit checking each position in a building for another unit. There's a function in the editor's depot that can count the number of buildingpos in a building.

My solution may seem simple, but sometimes the simplest solutions are the best.

Hope this helps
Gruntage
"But one thing I can tell you from not just OFP but life in general:  criticism is directly proportional to quality. The more criticism a mission receives, the better the outcome" - macguba

Offline Nikiller

  • Nogova Most Wanted
  • Members
  • *
  • ofp scripting addict
    • [LOL] ArmA ofp Site
Re: How to check if a unit is inside a building (i.e 2nd floor)
« Reply #2 on: 20 Sep 2012, 13:57:16 »
hi,

Interesting. Alright, first of all, please could you remove your signature? Images (both animated and inanimated) are not permitted as signatures here.

Done. Sorry I didn't know.

Thanks for the fast reply, but that's not exactly what I'm looking for. My request should have been more precise. I'm asking for universal soultion to check if a unit is inside any enterable building anywhere on the island.

I think the way to go would be a condition who check if the unit is above the ground even if it is inside a building. Only gamelogic change their height when they are placed in a building predefined position. I would like something like modelToWorld command in ArmA2, (maybe a function?).

cya.

Nikiller.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: How to check if a unit is inside a building (i.e 2nd floor)
« Reply #3 on: 20 Sep 2012, 19:25:53 »
Well, after some tinkering in OFP (sqs scripting is absolutely horrifying now :P ) did something like this:
- download this aslheight function
- in init.sqs:
Code: [Select]
getASL = preprocessFile "aslheight.sqf"- check.sqs:
Code: [Select]
#loop1
~0.5
_building = nearestBuilding _this

? ((_this distance _building)<=6): goto "in"
? (!alive _this): exit
goto "loop1"

#in
_logic = "logic" camCreate (position _building)

#loop2
_first = true
_upper = false
_uhgt = [_this] call getASL
_lhgt = [_logic] call getASL

? (_uhgt-_lhgt) >= 5: _upper = true; _first = false
hint format ["higher floor: %1\n1st floor: %2\n%3",_upper,_first]

? (_this distance _building)>6: deleteVehicle _logic; _first = true; _upper = false; goto "loop1"
? !alive _this: goto "exit"
~0.5
goto "loop2"

#exit
deleteVehicle _logic
exit
- run the script from player's init:
Code: [Select]
this exec "check.sqs"
Of course that's just kinda proof of concept but what you want might perhaps be possible, at least this shows you going into a building and "detects" upper floor correctly (in my very short test :whistle:). :dunno:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Nikiller

  • Nogova Most Wanted
  • Members
  • *
  • ofp scripting addict
    • [LOL] ArmA ofp Site
Re: How to check if a unit is inside a building (i.e 2nd floor)
« Reply #4 on: 20 Sep 2012, 21:13:47 »
hi,

Thanks h-. Very smart to check the sea level instead of the ground level :good:. Now I know how I will do it.

I finish the script and post it in this topic when RL allows me to do it, maybe it will be usefull for someone else.

Thanks again Gruntage and h- for taking the time to help me.

cya.

Nikiller.

EDIT: Most of time if a player is at building upper floors, enmies will stay outside doing nothing but be shot like ducks. I have a first version of the script. It stills early beta so sometimes the scripts fails to send AI in the building. Some stuffs could also be made in more elegant way, feel free to modify.

It checks if a unit is inside a building. If the unit is inside it checks if its height is more than 3m. If its height is more than 3m the script determine which is the unit nearest buildingPos and send an attacker to this position.

It still needs value tweak to set the script for most buildings but overall it works.

Looking for beta testers.

init.sqs
Code: [Select]
;*******************************
;Init Script by Nikiller v0.9b
;contact: nikillerofp@hotmail.fr
;*******************************

nik_faslheight=preProcessFile "aslheight.sqf"

exit

aslheight.sqf
Code: [Select]
/*----------------------------------------------------------------------------------------------------------------------
Computes the height above sea level
© by TakeOffTim
Wenn ihr diese Funktion in eurer Mission benutzen wollt, vermerkt bitte, dass sie von mir ist.
If you want to use this function in your mission, please make a note that I´ve made it.
----------------------------------------------------------------------------------------------------------------------*/

private ["_unit","_logic","_x","_y","_xLog","_yLog","_dist","_ground"];

_unit = _this select 0;
_logic = "logic" camCreate [0,0,0];

_x = getpos _unit select 0;
_y = getpos _unit select 1;
_dist = _logic distance _unit;
_ground = (_x ^ 2) + (_y ^ 2);

deleteVehicle _logic;

sqrt ((_dist ^ 2) - _ground)

check_inside.sqs
Code: [Select]
;***************************************************************************
;Check Inside Script by Nikiller v0.9b
;Check if target is inside a building and send AI to his nearest buildingpos
;Note: Place a game logic named server on the map
;Credits: Use aslheight © by TakeOffTim, proof of concept by h-
;contact: nikillerofp@hotmail.fr
;[targetName,searcherName] exec "scriptName.sqs"
;***************************************************************************

if (local server) then {} else {goto "ende"}

_u = _this select 0
_z = _this select 1

#main
~5
? !(alive _u) || !(alive _z): goto "ende"
_building = nearestBuilding _u
? _u distance _building<=6: goto "near"
goto "main"

#near
_logic="logic" createVehicle [0,0,0]
_logic setPos (getPos _building)

#height
? !(alive _u) || !(alive _z): goto "ende"
_uhgt=[_u] call nik_faslheight
_lhgt=[_logic] call nik_faslheight
? (_uhgt-_lhgt)>=3: goto "chase"
? (_u distance _building)>6: deleteVehicle _logic; goto "main"
~1
goto "height"

#chase
_cnt=0
_building=nearestBuilding _u
_gl="logic" createVehicle [0,0,0]

while {format["%1",_building buildingPos _cnt]!="[0,0,0]"} do {_cnt=_cnt+1}

#search
~1
? !(alive _u) || !(alive _z): goto "ende"
_gl setPos (_building buildingPos _cnt)
? _u distance _gl <2: goto "found"
_cnt=_cnt-1
? _cnt>=0: goto "search"

#found
~0.5
_z doMove (_building buildingPos _cnt)
deleteVehicle _gl
goto "main"

#ende
{deleteVehicle _x} forEach [_gl,_logic]

exit

cya.

Nikiller.
« Last Edit: 22 Sep 2012, 21:25:11 by Nikiller »