自己写的死斗模式AI路点生成器,这样做联机任务就方便多了。但是没有用,不知道哪里错了或是怎么调用。求大神修改,感激不尽!
原理是在编辑器加4个标记,mark1,mark2...mark4(顺序如下)对于每个AI,随机时间后随机生成一个坐标并判断是否在4个标记围成的四边形中(凹四边形不行),如果不在就重新生成。
首先通过4个标记坐标确定一个小范围,避免在全地图中随机(节省资源),然后通过4点坐标计算围成的四边形每条边所在直线的解析式,并把随机点代入判断。
顺序
mk1 line1 mk2
line4 line2
mk4 line3 mk3
Waypoint.spf源码
_hunit = _This Select 0;
_hpos_x_1 = getMarkerPos hmark1 Select 0;
_hpos_x_2 = getMarkerPos hmark2 Select 0;
_hpos_x_3 = getMarkerPos hmark3 Select 0;
_hpos_x_4 = getMarkerPos hmark4 Select 0;
_hpos_y_1 = getMarkerPos hmark1 Select 1;
_hpos_y_2 = getMarkerPos hmark2 Select 1;
_hpos_y_3 = getMarkerPos hmark3 Select 1;
_hpos_y_4 = getMarkerPos hmark4 Select 1;
//draw lines
_h_k_1 = (_hpos_y_1 - _hpos_y_2) / (_hpos_x_1 - _hpos_x_2);
_h_k_2 = (_hpos_y_2 - _hpos_y_3) / (_hpos_x_2 - _hpos_x_3);
_h_k_3 = (_hpos_y_3 - _hpos_y_4) / (_hpos_x_3 - _hpos_x_4);
_h_k_4 = (_hpos_y_4 - _hpos_y_1) / (_hpos_x_4 - _hpos_x_1);
_h_b_1 = (_hpos_y_1 - _h_k_1 * _hpos_x_1);
_h_b_2 = (_hpos_y_2 - _h_k_2 * _hpos_x_2);
_h_b_3 = (_hpos_y_3 - _h_k_3 * _hpos_x_3);
_h_b_4 = (_hpos_y_4 - _h_k_4 * _hpos_x_4);
if (_hpos_x_2 >= _hpos_x_3) then {_hpos_x_right = _hpos_x_2 - _hpos_x_3} else {_hpos_x_right = _hpos_x_3 - _hpos_x_2};
if (_hpos_x_1 >= _hpos_x_4) then {_hpos_x_left = _hpos_x_1 - _hpos_x_4} else{_hpos_x_left = _hpos_x_4 - _hpos_x_1};
if (_hpos_y_2 >= _hpos_y_1) then {_hpos_y_up = _hpos_y_2 - _hpos_x_1} else {_hpos_y_up = _hpos_y_1 - _hpos_x_2};
if (_hpos_y_3 >= _hpos_y_4) then {_hpos_y_down = _hpos_y_3 - _hpos_y_4} else {_hpos_y_down = _hpos_y_3 - _hpos_y_4};
_hpos_x_long = _hpos_x_right - _hpos_x_left;
_hpos_y_long = _hpos_y_up - _hpos_x_down;
While {True} Do{
_hdo = 0;
_hpos_x_random = random _hpos_x_long; //Random real (floating point) value from 0 (inclusive) to x (not inclusive).
_hpos_y_random = random _hpos_y_long;
_hpos_x_final = _hpos_x_long + _hpos_x_left;
_hpos_y_final = _hpos_y_long + _hpos_y_down;
if (_h_k_1 * _hpos_x_final + _h_b_1 >= _hpos_y_final) then {_hdo = _hdo + 1};
if (_h_k_3 * _hpos_x_final + _h_b_3 <= _hpos_y_final) then {_hdo = _hdo + 1};
if ((_hpos_y_final - _h_b_4) / _h_k_4 <= _hpos_x_final) then {_hdo = _hdo + 1};
if ((_hpos_y_final - _h_b_2) / _h_k_2 >= _hpos_x_final) then {_hdo = _hdo + 1};
if (_hdo == 4) then {_hunit doMove [_hpos_x_final,_hpos_y_final,0]};
_hdo == 0;
_htime = 5 + random 10;
sleep _htime;
}; |