Getting an inversely proportionate value

Ladies, gentlemen.

I’m currently attempting to set up a system for equipped weapon stats, and I’ve run into an issue I’m not sure how to solve:

I’ve got a Float that represents the attack speed of the equipped weapon, the default of which is 1. This is used as the attack animation’s speed:

animation["Attack1"].speed = attackSpeed;

Further on in the code is a bit that uses WaitForSeconds to make it so you can’t attack again until X seconds have passed, the value of which should get lower the higher the weapon’s attack speed is, or vice-versa. The default of this one is .5.

So, for example, if the attack speed were 2, I’d say that X should be around .25. .5, and it’d be 1. How would one accomplish this?

In your Q title, you ask for the inverse. Why doesn't the actual inverse -- 1/attackSpeed -- work, or, in your case: Waitfor( 0.5f / attackSpeed)? I'd probably change attackSpeed to the actual delay in seconds, then use 2/attackSpeed for the animation speed.

–

1 Answer

1

Based on Owen’s comment, I figured it to be 1/(attackSpeed * 2)

Divided by 2 and times 0.5 are the same. I prefer 0.5/attackSpeed since it has your 0.5 base delay in it, adjusted by speed. Say you want 0.75 base delay, can change to 0.75/attackSpeed. With the attackSpeed/2 way, changing to a base delay of 0.75 comes out to the ugly attackSpeed/1.33333 (try it -- for ASsp=1 you get 1/1.333 = 0.75.)

–