PDA

View Full Version : two scripting questions



lethal
Dec 18 2006, 11:53
Over the last few days i have been trying to make myself a believable airstrike via scripts.

two scripts so far (nothing too complex http://forums.bistudio.com/oldsmileys/wink_o.gif ):

demo.sqs
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Targets = _This Select 0;
_Plane = _This Select 1;

_TargetCount = Count _Targets;
_x = 0;
#loop;
if &#40;_x &#62;= _targetcount&#41; then goto &#34;end&#34;;
_curTarget = _Targets select _x;
_Trigger = createTrigger &#91;&#34;EmptyDetector&#34;, position _curTarget&#93;;
_Trigger setTriggerArea &#91;400,400,0,false&#93;;
_Trigger setTriggerActivation &#91;&#34;VEHICLE&#34;,&#34;PRESENT&#34;,true&#93;;
_Trigger triggerAttachVehicle &#91;_Plane&#93;;
_Statement = Format&#91;&#39;&#91;%1,%2&#93; exec &#34;launch.sqs&#34;&#39;,_curTarget,_plane&#93;;
_Trigger setTriggerStatements &#91;&#34;this&#34;,_Statement,&#34;&#34;&#93;;
_x = _x + 1;
goto &#34;loop&#34;;
#end;[/QUOTE]

launch.sqs
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Target = _this select 0;;
_Launcher = _this select 1;

_TargetPos = GetPosASL _Target;
_LauncherPos = GetPosASL _Launcher;
_LauncherPos set &#91;2,&#40;&#40;_TargetPos Select 2&#41;+300&#41;&#93;;
_VectorToTarget = &#91;&#40;_TargetPos Select 0&#41;-&#40;_LauncherPos Select 0&#41;,&#40;_TargetPos Select 1&#41;-&#40;_LauncherPos Select 1&#41;,&#40;_TargetPos Select 2&#41;-&#40;_LauncherPos Select 2&#41;&#93;;
_Bomb = &#34;Bo_GBU12_LGB&#34; createvehicle &#91;0,0,0&#93;;
_VelocityX = &#40;_VectorToTarget Select 0&#41;/3.8;
_VelocityY = &#40;_VectorToTarget Select 1&#41;/3.8;
_VelocityZ = &#40;_VectorToTarget Select 2&#41;/3.8;
_Bomb setPosASL _LauncherPos;
_Bomb setVectorDir &#91;_VelocityX,_VelocityY,_VelocityZ&#93;;
_Bomb setVelocity &#91;_VelocityX,_VelocityY,_VelocityZ&#93;;[/QUOTE]

I am calling demo.sqs with
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">&#91;&#91;Impact1,Impact2,Impact3&#93;,Harrier1&#93; exec &#34;demo.sqs&#34;[/QUOTE]

Impact1-3 are gamelogics i set up for simulating a ripple of 3 bombs.

Harrier1 is the AV8B overflying the area. Here&#39;s it&#39;s init field:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this FlyInHeight 400;[/QUOTE];


Now for the questions:

1) is there a formula i can use for determining the correct velocity vector for the bombs? i&#39;ve been estimating the values which results in them being correct only at one specific launch-height and -distance.

2) i&#39;ve recently added the second script &#39;demo.sqs&#39; to enable multiple targets in one single pass. at first only one bomb was fired - after a bit of tinkering i thought i fixed the problem but for some reason there aren&#39;t any bombs dropped now and i don&#39;t know what the problem is.

ps: i&#39;m pretty tired so it&#39;s quite possible that i simply don&#39;t see the obvious http://forums.bistudio.com/oldsmileys/wink_o.gif

lethal
Dec 20 2006, 04:08
I&#39;ve rewritten the scripts several times now and tried different approaches. one of then involved using slant range and angle for release point calculation and now i&#39;m trying something called ccip (continuesly calculated impact point) some of you may know from other simulators.
but the problem persists - it eventually comes down to either finding the right formula (in this case one which predicts the impact point derived from the speed(-vector) and the height above groundor estimating it which isn&#39;t optimal.
Secondly i&#39;d like to include some kind of tracking for the falling bomb. as you can see from the previous scripts i posted, i&#39;ve been experimenting with simply assinging a new velocity vector to the bomb guiding it to the target but that is far from perfect. there are no inflight updates there and the velocity vector of the bomb is completely detached from the launching aircraft...

I&#39;d be happy for any any tips regarding any aspect of this little &#39;project&#39; of mine http://forums.bistudio.com/oldsmileys/smile_o.gif

ps: heres one of my little experiments; this is still purely sqs, i am moving to sqf for some parts now because of the speed difference some have reported.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Plane = _this select 0;
_Target = _this select 1;

;_Ripple = _this select 2;
;_Interval = _this select 3;
;not used atm

_TargetPosASL = GetPosASL _Target;

#launchloop
_PlanePosASL = GetPosASL _Plane;
_HeightAboveTarget = &#40;&#40;_PlanePosASL Select 2&#41; - &#40;_TargetPosASL Select 2&#41;&#41;;
_GroundDistanceToTarget = &#91;&#40;_PlanePosASL Select 0&#41;,&#40;_PlanePosASL Select 1&#41;,&#40;_TargetPosASL Select 2&#41;&#93; Distance _TargetPosASL;
_CurrentSlantRange = sqrt&#40;&#40;_HeightAboveTarget^2&#41;+&#40;_GroundDistanceToTarget^2&#41;&#41;;
_CurrentSlantAngle = asin&#40;_HeightAboveTarget/_CurrentSlantRange&#41;;
_WantedSlantAngle = 27;
;this is an estimated value i determined by experimentation
If &#40;_WantedSlantAngle &#60;= _CurrentSlantAngle&#41; then {Goto &#34;Fire&#34;};
;hint format &#91;&#39;Height Above Target&#58; %1&#92;nDistance To Target&#58; %2&#92;nSlant Range&#58; %3&#92;nSlant Angle&#58; %4&#39;,_HeightAboveTarget,_GroundDistanceToTarget,_CurrentSlantRange,_CurrentSlantAngle&#93;;
~0.01
goto &#34;launchloop&#34;;

#Fire
_BombPos = &#91;&#40;Getpos _Plane Select 0&#41;,&#40;&#40;Getpos _Plane Select 1&#41;-5&#41;,&#40;Getpos _Plane Select 2&#41;&#93;
_Bomb = &#34;Bo_GBU12_LGB&#34; createVehicle _BombPos;
_AimVector = &#91;&#40;&#40;GetPos _Target Select 0&#41;-&#40;GetPos _Bomb Select 0&#41;&#41;,&#40;&#40;GetPos _Target Select 1&#41;-&#40;GetPos _Bomb Select 1&#41;&#41;,&#40;&#40;GetPos _Target Select 2&#41;-&#40;GetPos _Bomb Select 2&#41;&#41;&#93;;
_Bomb setVelocity &#91;&#40;&#40;_AimVector Select 0&#41;/2&#41;,&#40;&#40;_AimVector Select 1&#41;/2&#41;,&#40;&#40;_AimVector Select 2&#41;/2&#41;&#93;;
#guidance
_AimVector = &#91;&#40;&#40;GetPos _Target Select 0&#41;-&#40;GetPos _Bomb Select 0&#41;&#41;,&#40;&#40;GetPos _Target Select 1&#41;-&#40;GetPos _Bomb Select 1&#41;&#41;,&#40;&#40;GetPos _Target Select 2&#41;-&#40;GetPos _Bomb Select 2&#41;&#41;&#93;;
;hint format &#91;&#39;Aimvector = %1&#39;,_AimVector&#93;;
;this was meant to provide inflight guidance - i stopped because there were too many
;limitation in this approach and i want this to be as close to universial as possible
~0.01
If &#40;alive _Bomb&#41; then {goto &#34;guidance&#34;};
;hint = format &#91;&#39;Height Above Target&#58; %1&#92;nDistance To Target&#58; %2&#92;nSlant Range&#58; %3&#92;nSlant Angle&#58; %4&#39;,_HeightAboveTarget,_GroundDistanceToTarget,_CurrentSlantRange,_CurrentSlantAngle&#93;;
[/QUOTE]

Big Dawg KS
Dec 20 2006, 20:42
Um... you might want to try the good ole velocity (http://community.bistudio.com/wiki/velocity) command... Worked wonders in OFP. http://forums.bistudio.com/oldsmileys/whistle.gif

lethal
Dec 20 2006, 21:35
not to sound rude - but have you actually read my posts? i&#39;ve used velocity and setvelocity several times already...

question is which value to set it to so the falling object hits the intended target (and looks realistic). i can make the bomb simply zoom towards the target at high speed like a missile but that hardly looks convincing. i&#39;m looking for a nice, smooth curve with maybe slight corrections. one has to make allowances for arma&#39;s limited scale in comparison to &#39;serious&#39; flight simulators of course and maybe exaggerate drag a little among other this etc...

Big Dawg KS
Dec 20 2006, 21:56
not to sound rude - but have you actually read my posts?
TBH, not entirely, sorry.  http://forums.bistudio.com/oldsmileys/whistle.gif

In that case you may want to consider trajectories, acceleration due to gravity, air friction, etc... mainly stuff from basic physics courses. IMO you shouldn&#39;t need anything more advanced than that.

Edit: Here you go, High school physics/Projectile motion (http://en.wikibooks.org/wiki/High_school_physics/Projectile_motion)

lethal
Dec 20 2006, 22:28
not to sound rude - but have you actually read my posts?
TBH, not entirely, sorry. http://forums.bistudio.com/oldsmileys/whistle.gif

In that case you may want to consider trajectories, acceleration due to gravity, air friction, etc... mainly stuff from basic physics courses. IMO you shouldn&#39;t need anything more advanced than that.

Edit: Here you go, High school physics/Projectile motion (http://en.wikibooks.org/wiki/High_school_physics/Projectile_motion)
thanks for the link http://forums.bistudio.com/oldsmileys/smile_o.gif thb i&#39;ve never had stuff like that in high school but i guess i can still learn http://forums.bistudio.com/oldsmileys/wink_o.gif

Big Dawg KS
Dec 20 2006, 23:18
not to sound rude - but have you actually read my posts?
TBH, not entirely, sorry.  http://forums.bistudio.com/oldsmileys/whistle.gif

In that case you may want to consider trajectories, acceleration due to gravity, air friction, etc... mainly stuff from basic physics courses. IMO you shouldn&#39;t need anything more advanced than that.

Edit: Here you go, High school physics/Projectile motion (http://en.wikibooks.org/wiki/High_school_physics/Projectile_motion)
thanks for the link http://forums.bistudio.com/oldsmileys/smile_o.gif thb i&#39;ve never had stuff like that in high school but i guess i can still learn http://forums.bistudio.com/oldsmileys/wink_o.gif
Hehe, I guess I&#39;m glad to be one of the "odd" ones who actually believed it was valuable information being tought (and to think of all the people who said it had no practical use, ha&#33;..).  http://forums.bistudio.com/oldsmileys/nener.gif
Actually I learned a lot about certain things (vectors for example) from scripting in OFP before I ever covered it in school. Applying it to a virtual world like that makes it easier to visualize and understand. Maybe that&#39;s why I&#39;ve always done so well in those courses (but then again I&#39;ve always been good at those subjects long before I was introduced to OFP). http://forums.bistudio.com/oldsmileys/whistle.gif

OFP and ArmA are perfect examples of how useful it is to be able to express the universe in a bunch of numbers and equations.

lethal
Dec 21 2006, 10:18
not to sound rude - but have you actually read my posts?
TBH, not entirely, sorry. http://forums.bistudio.com/oldsmileys/whistle.gif

In that case you may want to consider trajectories, acceleration due to gravity, air friction, etc... mainly stuff from basic physics courses. IMO you shouldn&#39;t need anything more advanced than that.

Edit: Here you go, High school physics/Projectile motion (http://en.wikibooks.org/wiki/High_school_physics/Projectile_motion)
thanks for the link http://forums.bistudio.com/oldsmileys/smile_o.gif thb i&#39;ve never had stuff like that in high school but i guess i can still learn http://forums.bistudio.com/oldsmileys/wink_o.gif
Hehe, I guess I&#39;m glad to be one of the "odd" ones who actually believed it was valuable information being tought (and to think of all the people who said it had no practical use, ha&#33;..). http://forums.bistudio.com/oldsmileys/nener.gif
Actually I learned a lot about certain things (vectors for example) from scripting in OFP before I ever covered it in school. Applying it to a virtual world like that makes it easier to visualize and understand. Maybe that&#39;s why I&#39;ve always done so well in those courses (but then again I&#39;ve always been good at those subjects long before I was introduced to OFP). http://forums.bistudio.com/oldsmileys/whistle.gif

OFP and ArmA are perfect examples of how useful it is to be able to express the universe in a bunch of numbers and equations.
yeah - there are a few things one whished one had learned...
but in all honesty - there were a few things i could have skipped for more important stuff http://forums.bistudio.com/oldsmileys/wink_o.gif but not to wander OT here http://forums.bistudio.com/oldsmileys/biggrin_o.gif

bravo 6
Jan 2 2007, 20:24
does anyone have a pbo example of it?

would be very apreciated http://forums.bistudio.com/oldsmileys/smile_o.gif