Jump to content
Sign in to follow this  
dr_eyeball

setPos without building collision

Recommended Posts

<span style='color:maroon'>Query: Is there a technique or setPos equivalent command, which performs the same collision checking that createVehicle does?</span>

i.e. Something which positions the object (especially infantry & captives) to a suitable position nearby required position, without collision and not inside a building.

Example situation: initialise random position for stationary captives near random buildings (and some buildings have no buildingPos positions).

When you use createVehicle with a vehicle type, for example, it will ensure the vehicle is placed away from buildings, vehicles and other objects at the given position.

So the final position will be a position near the required position, if there is a collision.

I've been able to use a bit of a silly work around to achieve the same result during initialisation, but am looking for something better.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> // bit of a hack job to ensure setPos is not inside a wall, building or another vehicle or person

_tmpObject = "Landrover" createVehicle _pos; // let createVehicle find a suitable clear position

_clearPos = position _tmpObject; // new pos after object has found clear pos

deleteVehicle _tmpObject;

_object setPos _clearPos; // place object at clear pos

Share this post


Link to post
Share on other sites

Instead of creating a Landrover, create a game logic. And use "createvehiclelocal" here.

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

_clearPos = position _tmpObject;

deleteVehicle _tmpObject;

_object setPos _clearPos;

Letting "createvehicle" decide where the best position is works very reliable, but the down part is that the unit is several meters away from the desired position.

The following part is a different approach to it.

findposition.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private["_pos","_radius","_r","_logic","_found","_first","_newpos"];

_pos = _this select 0;

_radius = _this select 1;

_logic = "Logic" CreateVehicleLocal _pos;

_found = false;

_first = true;

_newpos = _pos;

_r = sqrt ((_radius * _radius) / 2);

while {!_found} do

{

if (_first) then

{

_first = false;

_logic setpos _newpos;

_newpos = getpos _logic;

}

else

{

_logic setpos [(_newpos select 0) + _r - random (2*_r),(_newpos select 1) + _r - random (2*_r), _newpos select 2];

_newpos = getpos _logic;

};

private["_house"];

_house =  nearestObjects [_newpos,["ALLVEHICLES","STATIC","THING"],_radius];

if (!SurfaceIsWater _newpos && count _house == 0) then

{

_found = true;

_pos = _newpos;

};

};

deletevehicle _logic;

findPosition_safepositiondone = true;

_pos

it creates a gamelogic at the given position, checks if there are any objects within the given radius. If there's one it checks another random position close to the original position.

the calculated random position is based on the given radius.

setPosMyObject.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private["_pos","_goodpos","_obj"];

_obj = _this select 0;

_pos = _this select 1;

findPosition_safepositiondone = false;

_goodpos = [_pos,3] call fFindPosition;

@findPosition_safepositiondone

_obj setPos _goodpos;

exit;

this one runs the function, waits for it to finish and then sets the position.

you may change the radius (here: 3) depending on the enviroment you put the unit/object in.

and put this in your init.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">fFindPosition = compile loadfile "findposition.sqf";

and run the whole thing with this command:

[OBJECT,POSITION] exec "setPosMyObject.sqs";

for example: [soldier1, getPos player] exec "setPosMyObject.sqs"

feel free to edit that function in order to get better results.

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  

×