mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Align trench to ground surface to avoid having to lower them too much on slopes
This commit is contained in:
parent
b20a2f338b
commit
d2d7e46401
@ -20,25 +20,44 @@ params ["_unit"];
|
||||
// enable running again
|
||||
[_unit, "forceWalk", "ACE_Trenches", false] call EFUNC(common,statusEffect_set);
|
||||
|
||||
// delete placement dummy and create real trench
|
||||
// Delete placement dummy and create real trench
|
||||
[{
|
||||
params ["_unit"];
|
||||
if (isNull GVAR(trench)) exitWith {};
|
||||
|
||||
params ["_unit"];
|
||||
deleteVehicle GVAR(trench);
|
||||
private _trench = createVehicle [GVAR(trenchType) select 0, [0, 0, 0], [], 0, "NONE"];
|
||||
|
||||
GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"];
|
||||
private _position = getPosASL GVAR(trench);
|
||||
private _basePos = GVAR(trenchPos);
|
||||
private _angle = (GVAR(digDirection) + getDir _unit);
|
||||
private _minz = (getTerrainHeightASL _position);
|
||||
_position set [2, _minz + _offset];
|
||||
private _v3 = [sin _angle, +cos _angle, 0] vectorCrossProduct surfaceNormal _position;
|
||||
private _v1 = (surfaceNormal _position) vectorCrossProduct _v3;
|
||||
|
||||
deleteVehicle GVAR(trench);
|
||||
// _v1 forward from the player, _v2 to the right, _v3 points away from the ground
|
||||
private _v3 = surfaceNormal _basePos;
|
||||
private _v2 = [sin _angle, +cos _angle, 0] vectorCrossProduct _v3;
|
||||
private _v1 = _v3 vectorCrossProduct _v2;
|
||||
|
||||
private _trench = createVehicle [GVAR(trenchType) select 0, [0, 0, 0], [], 0, "NONE"];
|
||||
_trench setPosASL _position;
|
||||
_trench setVectorDirAndUp [_v1, surfaceNormal _position];
|
||||
// Stick the trench to the ground
|
||||
_basePos set [2, getTerrainHeightASL _basePos];
|
||||
private _minzoffset = 0;
|
||||
private ["_ix","_iy"];
|
||||
for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do {
|
||||
for [{_iy = -_dy/2},{_iy <= _dy/2},{_iy = _iy + _dy/3}] do {
|
||||
private _pos = _basePos vectorAdd (_v2 vectorMultiply _ix)
|
||||
vectorAdd (_v1 vectorMultiply _iy);
|
||||
_minzoffset = _minzoffset min ((getTerrainHeightASL _pos) - (_pos select 2));
|
||||
#ifdef DEBUG_MODE_FULL
|
||||
_pos set [2, getTerrainHeightASL _pos];
|
||||
_pos2 = +_pos;
|
||||
_pos2 set [2, getTerrainHeightASL _pos + 1];
|
||||
drawLine3D [ASLtoAGL _pos, ASLtoAGL _pos2, [1,1,0,1]];
|
||||
#endif
|
||||
};
|
||||
};
|
||||
_basePos set [2, (_basePos select 2) + _minzoffset + _offset];
|
||||
TRACE_2("",_minzoffset,_offset);
|
||||
_trench setPosASL _basePos;
|
||||
_trench setVectorDirAndUp [_v1, _v3];
|
||||
|
||||
GVAR(trench) = objNull;
|
||||
}, [_unit], 1] call EFUNC(common,waitAndExecute);
|
||||
|
@ -38,6 +38,7 @@ GVAR(digDirection) = 0;
|
||||
// pfh that runs while the dig is in progress
|
||||
GVAR(digPFH) = [{
|
||||
(_this select 0) params ["_unit", "_trench"];
|
||||
GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"];
|
||||
|
||||
// Cancel if the helper object is gone
|
||||
if (isNull _trench) exitWith {
|
||||
@ -50,19 +51,25 @@ GVAR(digPFH) = [{
|
||||
};
|
||||
|
||||
// Update trench position
|
||||
private _basePos = eyePos _unit vectorAdd (positionCameraToWorld [0, 0, 2] vectorDiff positionCameraToWorld [0, 0, 0]);
|
||||
GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"];
|
||||
private _basePos = eyePos _unit vectorAdd ([sin getDir _unit, +cos getDir _unit, 0] vectorMultiply 2);
|
||||
|
||||
private _angle = (GVAR(digDirection) + getDir _unit);
|
||||
|
||||
// Stick the trench to the ground
|
||||
GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"];
|
||||
private _minz = (getTerrainHeightASL _basePos);
|
||||
private ["_ix","_iy"];
|
||||
/*for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do {
|
||||
for [{_iy = -_dy/2},{_iy <= _dy/2},{_iy = _iy + _dy/3}] do {
|
||||
private _pos = _basePos vectorAdd ([cos _angle, -sin _angle, 0] vectorMultiply _ix)
|
||||
vectorAdd ([sin _angle, +cos _angle, 0] vectorMultiply _iy);
|
||||
_minz = _minz min (getTerrainHeightASL _pos);
|
||||
// _v1 forward from the player, _v2 to the right, _v3 points away from the ground
|
||||
private _v3 = surfaceNormal _basePos;
|
||||
private _v2 = [sin _angle, +cos _angle, 0] vectorCrossProduct _v3;
|
||||
private _v1 = _v3 vectorCrossProduct _v2;
|
||||
|
||||
// Stick the trench to the ground
|
||||
_basePos set [2, getTerrainHeightASL _basePos];
|
||||
private _minzoffset = 0;
|
||||
private ["_ix","_iy"];
|
||||
for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do {
|
||||
for [{_iy = -_dy/2},{_iy <= _dy/2},{_iy = _iy + _dy/3}] do {
|
||||
private _pos = _basePos vectorAdd (_v2 vectorMultiply _ix)
|
||||
vectorAdd (_v1 vectorMultiply _iy);
|
||||
_minzoffset = _minzoffset min ((getTerrainHeightASL _pos) - (_pos select 2));
|
||||
#ifdef DEBUG_MODE_FULL
|
||||
_pos set [2, getTerrainHeightASL _pos];
|
||||
_pos2 = +_pos;
|
||||
@ -70,14 +77,13 @@ GVAR(digPFH) = [{
|
||||
drawLine3D [ASLtoAGL _pos, ASLtoAGL _pos2, [1,1,0,1]];
|
||||
#endif
|
||||
};
|
||||
};*/
|
||||
_basePos set [2, _minz + _offset];
|
||||
};
|
||||
_basePos set [2, (_basePos select 2) + _minzoffset + _offset];
|
||||
TRACE_2("",_minzoffset,_offset);
|
||||
_trench setPosASL _basePos;
|
||||
_trench setVectorDirAndUp [_v1, _v3];
|
||||
GVAR(trenchPos) = _basePos;
|
||||
|
||||
private _v3 = [sin _angle, +cos _angle, 0] vectorCrossProduct surfaceNormal _basePos;
|
||||
private _v1 = (surfaceNormal _basePos) vectorCrossProduct _v3;
|
||||
|
||||
_trench setVectorDirAndUp [_v1, surfaceNormal _basePos];
|
||||
}, 0, [_unit, _trench]] call CBA_fnc_addPerFrameHandler;
|
||||
|
||||
// add mouse button action and hint
|
||||
|
Loading…
Reference in New Issue
Block a user