Jump to content
Luft08

Ensuring objects are placed on level ground

Recommended Posts

I'm writing a mission that randomly creates camp sites in forested areas. However, sometimes the spot picked to place campfires is sloped making the scene look stupid.

 

Is there any way to ensure that objects are placed on level or near level ground?

 

Thanks.

Share this post


Link to post
Share on other sites

Like HazJ showed those are the functions you need. What I use is this:

 

_obj setVectorUp surfaceNormal (getposATL _obj);

 

where _obj is the object you want to align to the terrain

 

  • Like 2

Share this post


Link to post
Share on other sites

Finding flat spots in forests is tricky, since most of the built in SQF commands like isFlatEmpty will fail due to the object/tree density.

 

18 hours ago, Rydygier said:

As for dynamic camps etc. placement, you can get nice results with these:

 

isFlatEmpty

findEmptyPosition

BIS_fnc_findSafePos

selectBestPlaces

 

Some of them should solve your problem with slopes by ensuring, picked position will be flat/level enough.

 

Those won't really help him.

 

A function like getTerrainHeightASL is more useful for solving this problem.

 

You'll need to test different positions for flatness (within a radius).

 

A way to do that is to get a reference position (random position), then get 6-12 radial positions around it in all directions. Then calculate the angle of the Z-axis (height) delta of each of those positions from the reference position. If some of those radial positions Z-axis are much different from the Z of the reference position, then a slope exists at that site.

 

Iterate over the random pos code until you've found a position where the Z axis is consistent.

 

here is how I attempted it:

 

https://github.com/auQuiksilver/Apex-Framework/blob/master/Apex_framework.terrain/code/functions/fn_areaGradient.sqf

 

https://github.com/auQuiksilver/Apex-Framework/blob/master/Apex_framework.terrain/code/functions/fn_terrainGradAngle.sqf

 

And in practice, I used it to find a Forested + Flat position with a block like this:

 

https://github.com/auQuiksilver/Apex-Framework/blob/master/Apex_framework.terrain/code/functions/fn_SMregenerator.sqf#L21-L41

 

 

_bestPlaces = '(1 + forest) * (1 - houses)';
private _nearestTerrainObjects = [];
_basePosition = markerPos 'QS_marker_base_marker';
_baseRadius = 1500;
_fobPosition = markerPos 'QS_marker_module_fob';
_fobRadius = 300;
_posGradient = 0;
for '_x' from 0 to 99 step 1 do {
	_spawnPosition = ['WORLD',-1,-1,'LAND',[1.5,0,0.1,3,0,FALSE,objNull],TRUE,[[0,0,0],300,_bestPlaces,15,3],[],FALSE] call (missionNamespace getVariable 'QS_fnc_findRandomPos');
	_posGradient = [_spawnPosition,12] call (missionNamespace getVariable 'QS_fnc_areaGradient');
	if (
		((_usedPositions inAreaArray [_spawnPosition,500,500,0,FALSE]) isEqualTo []) &&
		((_allPlayers inAreaArray [_spawnPosition,500,500,0,FALSE]) isEqualTo []) &&
		(!([_spawnPosition,150,8] call (missionNamespace getVariable 'QS_fnc_waterInRadius'))) &&
		((_spawnPosition distance2D _basePosition) > _baseRadius) &&
		((_spawnPosition distance2D _fobPosition) > _fobRadius) &&
		((_spawnPosition distance2D (missionNamespace getVariable 'QS_aoPos')) > 1000) &&
		((_posGradient < 5) && (_posGradient > -5)) &&
		(((_spawnPosition select [0,2]) nearRoads 100) isEqualTo [])
	) exitWith {};
};

 

  • Like 4
  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, fn_Quiksilver said:

Those won't really help him.

 

Depends. I'm using those in Pilgrimage with satisfactory (to me) results, where I'm doing exactly that: spreading dynamically small encampments etc. also in the woods. Of course, as a part of bigger seeking algorithm, not just bare command. 

 

 

  • Like 1

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

×