Hello community,
I’m looking for some assistance on a C# script I am writting. I have a gattling gun that uses RayCasting for firing. I’m utilizing a custom cooldown system, but am having difficulty with the scripting to make it frame-rate-independent. I realize this is done by multiplying in the Time.DeltaTime, however the exact maths escape me. Can someone possibly assist? Here is what I have (with everything but the cooldown system ripped out):
void Update () { //TURRET ROTATION SCRIPTS HERE //Handle the input commands HandleActionInput(); //Decrement the Cooldowns if they are above 0.0 if (cd_GattlingCooldown > 0) cd_GattlingCooldown -= cd_GattlingRecovery; } void HandleActionInput() { if (Input.GetButton("Fire1")) { if (cd_GattlingCooldown <= 0) Fire(); } } void Fire() { cd_GattlingCooldown += cd_Gattling; GattlingRayCast(); }
cd_GattlingCooldown is set to 0. This is decremented until 0 by the cd_GattlingRecovery (1f) on each Update
cd_Gattling is total cooldown time applied when Gattling is fired (20f)
This is working great and I like the numbers as they are, but I’m trying to incorporate Time.DeltaTime to make it so framerates do not effect fire rate.
Does anyone with a stronger handle on maths able to assist me? Thank you in advance!