KaRRiLLioN 0 Posted April 23, 2003 Trig used to be my strong point, but when it comes to scripting I have a hard time visualizing the code. I'm trying to take a chopper that is flying, and when it gets within a certain range of an invisible helo pad, land precisely on it. I'm using SetVelocity right now, and I can make it land pretty well, but not perfectly on buildings, which is what I want. It's a littlebird BTW. What I'll need to do is guide it in whichever direction it needs to be in to land right on the spot. I know how to use Setvelocity and trigonometry to make the helo go faster/slower in the direction that it is already traveling in, just not how to calculate whether to go left or right to get right on a target. Got any ideas? Share this post Link to post Share on other sites
Guest Posted April 23, 2003 Code snippet from torpedo guidance script. The principle for your problem should be the same. _tPos = position of the target _pos = position of your vehicle _v0 = speed (m/s) It could be written more compact, but I havn't cleaned up the code yet. Also you should change the velocity on the z-axis to suit the helicopter needs (vertical speed is not relevant to a torpedo ) </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _tPos = getPos(_target) _pos = getPos(_vehicle) _v0 = 35 _dx = (_tPos select 0) - (_pos select 0) _dy = (_tPos select 1) - (_pos select 1) _fx= 0 ?_dx>0:_fx=1 _uDir = 360 - (atan( _dy/_dx) + 90 +  _fx*180) _vehicle setDir  (_uDir ) _vBase = [sin(_uDir),cos(_uDir), 0] _vehicle setVelocity  [(_vBase select 0)*_v0,(_vBase select 1) * _v0, -1] <span id='postcolor'> Edit: Here you have an addition for the z-axis angle: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_dx = (_tPos select 0) - (_pos select 0) _norm = sqrt(_dx^2 + _dy^2) _theta = abs(atan(_dz/_norm)) <span id='postcolor'> _theta = z angle to x-y plane Share this post Link to post Share on other sites
Pennywise 0 Posted April 24, 2003 Here is a small section of some code I wrote for a para drop script.  It flies to an exact location and deploys its cargo (troops). </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE"> ;========================================================= ;Move to drop area ;========================================================= _m241 setcombatmode "BLUE" _m241 setbehaviour "CARELESS" _Driver doMove getpos _paraDropHere ;_Driver globalChat "Moving Chopper" _m241 flyInHeight 80 _parapos   = getpos _paraDropHere _para_rsx  = _parapos select 0 _para_rsy  = _parapos select 1 _para_rsz  = _parapos select 2 #ParaLoop _chpprpos   = getpos _m241 ~.2 _chppr_rsx= _chpprpos select 0 _chppr_rsy= _chpprpos select 1 _chppr_rsz= _chpprpos select 2 ~.2 _diffx   = abs (_chppr_rsx-_para_rsx) _diffy   = abs (_chppr_rsy-_para_rsy) ~.2 ?((_diffx<=_disFromDrop) and (_diffy<=_disFromDrop)):goto "DeployTroops" <span id='postcolor'> This is another script I wrote to control the speed of the F18 hornet when the AI fly it.  It keeps the AI from flying at insane speeds all the time. </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE"> _obj    = _this select 0 _Soldier  = _this select 1 _spdMode  = speedMode _obj ;========================================================= ;Speed Offset ;========================================================= _SpdOffset = 1 ;========================================================= ;Fleight Altitude ;========================================================= _Altitude  = 200 ;========================================================= ;Speeds ;========================================================= _limited = 65 _normal  = 125 ;========================================================= ;Speed Control for AI ;========================================================= _obj flyinheight _Altitude ;========================================================= ;Speed Control for AI ;========================================================= ?(agvdebugCustomAddon):_Soldier globalChat "AI Speed Offset" ?(agvdebugCustomAddon):_Soldier globalChat Format["AI Speed Mode: %1", _spdMode] #AdjustSpeed _tempVel=velocity _obj _vX=_tempVel select 0; _vY=_tempVel select 1; _vZ=_tempVel select 2 _spdMode=speedMode _obj ?(_spdMode == "LIMITED" and (_vX > _limited)):_vX=(_vX/(abs _vX))*(_vX-_SpdOffset) ?(_spdMode == "LIMITED" and (_vY > _limited)):_vY=(_vY/(abs _vY))*(_vY-_SpdOffset) ?(_spdMode == "LIMITED" and (_vZ > _limited)):_vZ=(_vZ/(abs _vZ))*(_vZ-_SpdOffset) ?(_spdMode == "NORMAL" and (_vX > _normal)):_vX=(_vX/(abs _vX))*(_vX-_SpdOffset) ?(_spdMode == "NORMAL" and (_vY > _normal)):_vY=(_vY/(abs _vY))*(_vY-_SpdOffset) ?(_spdMode == "NORMAL" and (_vZ > _normal)):_vZ=(_vZ/(abs _vZ))*(_vZ-_SpdOffset) _obj setVelocity [_vX, _vY, _vZ] ?(!(_Soldier in _obj) or !(alive _Soldier)):goto "Exit" ~.03 goto "AdjustSpeed" #Exit ?(agvdebugCustomAddon):_Soldier globalChat "AI Speed Offset Exit" exit <span id='postcolor'> If you combine the two, Im sure you will come up exactly with what you need.  I can send you the actual scripts if you want.  You know my contacts:) Hope it helps ya out. Share this post Link to post Share on other sites
Kinnon 0 Posted April 27, 2003 If you don't mind using someone elses code, snypir of www.ofpec.com has written a script that fully encapsulates everything you need. I FULLY DONT SUPPORT THE OIL WAR Share this post Link to post Share on other sites
Guest Posted April 27, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Pennywise @ 25 April 2003,01:29)</td></tr><tr><td id="QUOTE">Here is a small section of some code I wrote for a para drop script. Â It flies to an exact location and deploys its cargo (troops). If you combine the two, Im sure you will come up exactly with what you need. Â I can send you the actual scripts if you want. Â You know my contacts:)<span id='postcolor'> The paradrop script is from what I understand not what he is looking for since they do not set the direction of the aircraft (setDir) towards the target. Depending on the relative position of the target both your chopper will fly sideways or even backwards Share this post Link to post Share on other sites
KaRRiLLioN 0 Posted April 28, 2003 The torpedo calculations seem to work fairly well, although I haven't incorporated the Z axis into it. The AI seems to get the chopper fairly close to where I want it to go, so what I'm doing now is letting the AI get it close and then I nudge it with a setvelocity and that seems to put it where I want it. Thanks! Share this post Link to post Share on other sites