Thanks Alex, I'll keep trying different things until that work.
Actually, I'm wondering if the weapon that will use such a script should be burst firing or just a regular one.
Seems like the burst mecanism may be usefull to determine if we're firing in the same spooling up sequence, but that may also be the thing that prevent the script from working.
I've tried variation of that :
Spoiler
cooldown = weapon.getCooldown();
if (weapon.isFiring() && cooldown >= minCooldown) {
firerate = 1 / cooldown;
nextFirerate = firerate + increment;
nextCooldown = 1 / nextFirerate;
weapon.setRemainingCooldownTo(nextCooldown);
}
Dunno if isFiring() is better than getChargeLevel() >= 1f, but I don't see any change ingame.
Edit : Found something that seems to work better, by using intervals :
Spoiler
charge = weapon.getChargeLevel();
if (charge >= 0.9f) {
if (!hasFired){
fireInterval.advance(amount);
if (fireInterval.intervalElapsed()) {
fireInterval.setInterval(0f, 1f);
hasFired = true;}
}
if (hasFired = true) {
spoolUpInterval.advance(amount);
if (!spoolUpInterval.intervalElapsed()) {
cooldown = weapon.getCooldown();
if (cooldown >= minCooldown) {
firerate = 1 / cooldown;
nextFirerate = firerate + (increment * spoolUpInterval.getElapsed());
nextCooldown = 1 / nextFirerate;
weapon.setRemainingCooldownTo(nextCooldown);
}
spoolUpInterval.advance(amount);
} else if (spoolUpInterval.intervalElapsed() && charge >= 0.5f) {
cooldown = minCooldown;
}
}
}
With that bit of code, the weapon is actually spooling up, but there is some unpredictible "cut" in the firing sequence. Also, the spool up ramp seems pretty long, looks like the firerate increase only once every three seconds or more. Any ideas on how to reduce that ramp, and why does the gun can randomly stop firing (with resuming it's spool up sequence or starting another one from 0)
Small update (but I'm still stuck !) :
I was tried to clean up my code, and end up with something that should work... If I manage to calculate if the weapon fired when the cooldown of the last shoot ended (so, the player/AI keep firing with that weapon), or if the delay was at least frame longer (meaning that during the same amount of time (here, cooldown of the last shoot elasped + 1 frame), the fire button wasn't pressed) and I can't find how to get that.
The cleaned code for the firerate (should work better with getCooldownRemaining, doesn't require a interval to ramp up or down, juste a +/- in front of the value that have to increment/decrement the firerate. Also check if we were already at the max/min firerate/cooldown, and spooling up/down ramps are more easy to work with) :
Spoiler
cooldown = weapon.getCooldownRemaining();
nextFirerate = 0f;
firerate = 1 / cooldown;
if (firedLastInterval) {
if (cooldown > minCooldown) {
nextFirerate = firerate + modifier; //* spoolingInterval.getElapsed())
} else {
weapon.setRemainingCooldownTo(minCooldown);
}
} else if (!firedLastInterval) {
if (cooldown < maxCooldown) {
nextFirerate = firerate - modifier; //* spoolingInterval.getElapsed())
} else {
weapon.setRemainingCooldownTo(maxCooldown);
}
}
if (nextFirerate != 0f) {
nextCooldown = 1 / nextFirerate;
weapon.setRemainingCooldownTo(nextCooldown);
}