Sorry, SM, I know you don't like double posts, but I feel bad about the code in the last post. I was in a hurry, and didn't proof it before I posted it.
This should be better.
Code: Select all
_numbomblets = 40;
_factor = 1;
// plane altitude modifier
_altMod = (_planeAlt - 50) / 5;
for [{_b = 1}, {_b <= 5}, {_b = _b + 1}] do
{
for [{_g = 1}, {_g <= _numbomblets}, {_g = _g + 1}] do
{
// Position the bomblet
_rndOffset = (random 180) - 90;
_dir = _bDir + _rndOffset;
if ((_dir > 360) || (_dir < 0)) then
{
_dir = abs (abs (_dir) - 360);
};
_dist = (random 20) + _altMod;
_newposx = (_bpos select 0) + sin (_dir) * _dist;
_newposy = (_bpos select 1) + cos (_dir) * _dist;
// Create the bomblet
_bomblet = _bt createVehicleLocal [_newposx, _newposy, _height];
if (VTE_debug) then
{
player sideChat format["%1 bomblet created at %2.",_bomblet, getPos _bomblet];
};
// Randomise the z velocity
_nvz = _bvz * ((60 + random 80) / 100);
// Re-speed the bomb
_factor = 2 * _b;
_bomblet setVelocity [_bvx * _factor, _bvy * _factor, _nvz];
};
//stutter preventing sleep
sleep .3;
// advance the spot to help elongate the dispersion
_dist = 10; // tweakable
_newposx = (_bpos select 0) + sin (_bDir) * _dist;
_newposy = (_bpos select 1) + cos (_bDir) * _dist;
_bpos = [_newposx, _newposy, 0];
};
}
else
{
hint "You must be above 50m to drop this ordnance.";
};
What I changed from what you posted last:
- changed the loop to more what I'm used to - the "for/next" style loop
- replaced the main loop with 2 loops
-- the "big" loop repeats 5 times
-- the small loop creates 40 bomblets - this is less than the 50 that didn't seem to cause any problems
- the pause (now, correctly) happens for .3 second AFTER the creation of each group of 40 bomblets
- after each bomblet creation loop, the bomb position is advanced 10m (that can be tweaked)
-- this should create a longer, more oval dispersion, more realistic
- total of 200 bomblets
The loops also allowed some variability to the vectors so that the ones towards the end have more random "forward" velocity than the ones at the beginning. My thought is that this will create some overlap between the groups, but the ones at the end may have more stragglers. I'm not sure this is the best implementation, though, so there is still some tweaking that may need to be done.