Harkonin 0 Posted September 24, 2003 Been working on a more intelligent AI script but have 1 problem. Ai takes cover using the knowsabout command. If uncertain of a units whereabouts I want them to take cover behind the nearestobject. so far I can only manage them to move to the nearest object with _ai domove getpos nearestobject. anyone know how I can get them to move to the nearest object and "behind it" as in the opposite direction of enemy forces. I assume i need some complicated sin cosin equation. Help appreciated thanks. Share this post Link to post Share on other sites
RED 0 Posted September 24, 2003 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _angle = ((shooter distance _ai) / (_ai distance nearestobject)) + 180 _dis = 1 _pos = [(getpos _unit select 0) + sin (_angle) * _dis, (getpos _unit select 1) + cos (_angle) * _dis,0] _ai domove _pos Something like that may work, I do not have time to test now so you will have to have a little play with it. There is an AI cover and hold script in the OFPEC script beta forum which you may like to take a look at, I can't get the link for you at the moment as the OFPEC seems to be having a few problems. RED Share this post Link to post Share on other sites
Harkonin 0 Posted September 24, 2003 no thats useless since they can't move anywhere, but thanks. Share this post Link to post Share on other sites
RED 0 Posted September 24, 2003 How do you mean? explain your problem more. RED Share this post Link to post Share on other sites
bn880 5 Posted September 24, 2003 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_angle = ((shooter distance _ai) / (_ai distance nearestobject)) + 180 _dis = 1 _pos = [(getpos _unit select 0) + sin (_angle) * _dis, (getpos _unit select 1) + cos (_angle) * _dis,0] _ai domove _pos What do you mean by this _angle = ? That doesn't give you any direction but a ratio of the distances. Share this post Link to post Share on other sites
RED 0 Posted September 24, 2003 Arg what was I thinking, you are correct. RED Share this post Link to post Share on other sites
bn880 5 Posted September 24, 2003 Don't worry about it RED, when it comes to finding solutions and making mistakes: Those who do, can. Those who don't, did. Or something like that. Share this post Link to post Share on other sites
Harkonin 0 Posted September 25, 2003 Heres the problem, I have the AI moving to the nearestobject on detection with - _ai domove (getpos nearestobject [0,0,0]) but they don't actually hide "behind" it as in the opposite direction the player is. I need something that will give them the position of the player and position of the nearest object and make them move behind the nearestobject accordingly. For example if the ai is 20 meters west of a bush or rock and the player is 40 meters south of the ai then the ai would move northeast behind the bush or rock. Dinger suggested this bit of code - _aix = _aip select 0 _aiy = _aip select 1 _objectp = getpos _object _objectx = _objectp select 0 _objecty = _objectp select 1 _box = _aix - _objectx _boy = _aiy - _objecty _d2d = sqrt (_box^2 + _boy^2) _distancebehind = 2 _dbx = _distancebehind * (_box/_d2d) _dby = _distancebehind * (_boy/_d2d) _resultx = _objectx + _dbx _resulty = _objecty + _dby _ai domove [_resultx, _resulty] but I can't seem to implement it. Any help is appreciated. Share this post Link to post Share on other sites
zayfod 1 Posted September 30, 2003 no thats useless since they can't move anywhere, but thanks. Eeeeeeeeeek, Im gonna cry now well it is a "hold" script, baaah "Im an artist, how am I sposed to work with all these amatuers" Um u could use toadys angle to object, I think its toadys, get the nearsestobjects "angle" and "distance" to the tango, then move the good guy till hes at the same angle but at a slightly further distance. Just a thought. might help Zay Toadys sqf function is at www.ofpec.com Share this post Link to post Share on other sites