nikiller 18 Posted September 20, 2012 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 or at least if enemy is at a floor. 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. Share this post Link to post Share on other sites
nikiller 18 Posted September 22, 2012 (edited) hi, 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 ;******************************* ;Init Script by Nikiller v0.9b ;contact: nikillerofp@hotmail.fr ;******************************* nik_faslheight=preProcessFile "aslheight.sqf" exit aslheight.sqf /*---------------------------------------------------------------------------------------------------------------------- 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 ;*************************************************************************** ;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. Edited September 22, 2012 by Nikiller Share this post Link to post Share on other sites