Jump to content
Sign in to follow this  
Harkonin

Ai cover script

Recommended Posts

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

<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
<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

Don't worry about it RED,

when it comes to finding solutions and making mistakes:

Those who do, can.

Those who don't, did. tounge_o.gif Or something like that.

Share this post


Link to post
Share on other sites

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
no thats useless since they can't move anywhere, but thanks.

Eeeeeeeeeek, Im gonna cry now crazy_o.gifsad_o.gif

well it is a "hold" script, baaah rock.gif

"Im an artist, how am I sposed to work with all these amatuers" tounge_o.gif

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. wink_o.gif might help

Zay

Toadys sqf function is at www.ofpec.com

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  

×