- Home /
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.
Ah, with a tiny adjustment, that first one worked. Thanks, ye! I was actually unaware of that inverse equation.
Answer by McMutton · Oct 07, 2011 at 08:24 PM
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.)
It's not so much that the 'base' value is .5, it's that .5 is the value I end up with if the weapon's attack speed is 1.
Your answer
Follow this Question
Related Questions
Maths issue + Null reference error? -1 Answers
How to create a standard deviation number generator? 2 Answers
What is the rotation equivalent of InverseTransformPoint? 3 Answers
How to get inverse of a lerp function 1 Answer
how to keep fraction number ??? 1 Answer