1
\$\begingroup\$

I'm developing an RPG and am stuck trying to create a formula for attack speed, using four stats and a base speed.

Basically, I'm trying to get an outcome where the encumbrance (basically weight and ease of handling in a single stat) of armor and weapon along with the players´ strength and agility will effect the attack speed.

So - for example: A player with a heavy armor and a 2-handed maul might end up with 0.35 attacks per second, while an unarmored dagger-wielding player should have around 2.5 or even 3 (which would be the maximum speed).

Weapons and armor have an encumbrance stat. Players have agility and strength.

In order to make it more realistic, I'm trying to integrate the following into the formula:

  • The penalty from the total encumbrance of all items should have a smaller impact on the attack speed than the encumbrance of the weapon
  • The penalty from the weapon encumbrance should depend on both agility and strength
  • There should be a maximum attack speed (around 3 attacks per second)
  • Higher agility should result in higher attack speed
  • Higher strength should lessen the overall encumbrance penalty

I'm not yet sure if the ranges or min/max stats are needed for the formula, but currently player stats will range between 1-10 and encumbrance (per item) from 1-10 as well.

I've given this a couple of hours of thought but I feel that my math skills might simply not be up to par.

Here's the current state of my attempt (non-functional): https://docs.google.com/spreadsheets/d/1S_NOsJp-FegY7ruR6EZTqWRxuP6gDnZJr9LYw8ETZKQ/edit#gid=0

\$\endgroup\$
0
\$\begingroup\$

Here goes one possible answer that can be further tweaked:

Let's first consider that your attack speed AS comes directly from agility modified by some constants, thus:

AS = Agility * alpha

If we say that Agility goes from 1 - 10, and alpha = 3/10, this means that at the lowest agility, you'd have 0.3 attacks per second and 3 attacks per second at the highest agility.

Now, we want encumbrance to modify this value, so adding to the equation gets us:

AS = (Agility * alpha) * EncMod,

where EncMod goes from 0.7 to 1.3 (or any other range, this is just to say it will modify the first portion of the equation by -30% to +30%).

EncMod will depend from both Strength and Agility, and will have an arbitrary range that must be converted to 0.7 to 1.3. Let's call this arbitrary encumbrance EncArb.

EncArb = 1/(EqEnc * 1/(Strength * gamma + Agility*sigma))

EqEnc is the encumbrance defined by equipment. This will be modified by strength and agility (modified by proportional contributions gamma and sigma). The inversions are somewhat messy, but they do the job here.

Putting it all together, we have:

EncMod = ((1.3 - 0.7)/(15-0.15))*EncArb + 0.7;

NOTE: Why 15 - 0.15? Those are the maximum and minimum EncArb values. They vary according to gamma, sigma, and maximum EqEnc, Agility and Strength. Those are sample values only.

Ok, time to put everything together. The final equation then is:

AS = ((Agility + beta)*alpha) * EncMod

(beta here is just helping the lowest attack speed not to fall too much).

To give some illustrative values:

I have set

gamma  = 1
sigma  = .5
alpha  = 2.25
beta   = 0.75

Agility, Strength, and EqEnc all varying between 1 and 10.

So:

Ag = 10, St = 10, EqEnc = 1 --> AS = 3.1
Ag = 1, St = 1, EqEnc = 10 --> AS = 0.28
Ag = 5, St = 5, EqEnc = 5 --> AS = 0.98
Ag = 5, St = 10, EqEnc = 5 --> AS = 1.03

As you can see, you still need to play a bit with gamma and sigma values to make it more balanced (and make strength less useless), but this is more a matter of adjusting the values rather than the calculation.

\$\endgroup\$
  • \$\begingroup\$ Thank you! I didn't end up using the exact same formula, but it helped a lot \$\endgroup\$ – Adam Gerthel Jan 22 at 13:55
1
\$\begingroup\$

I'd say start easy, there's actually not much math in here.

  • What is the default attack speed? Let's say it's 2 attacks per second.
  • Now you add to the formula the encumbrance of the weapon. What's the maximum encumbrance that you want to have? How slow is the slowest weapon? Let's say it's a giant two-handed hammer that can only do half the attacks, i.e. 1 per second. That means the weapon encumbrance has to be such that it halves the attacks per second. So, you need a number that multiplied by 2 gives you 1, which is 0.5. The slowest weapon has an encumbrance of 0.5.
  • Now add the encumbrance of the inventory. Again, what's the slowest you can get? Let's say the maximum penalty is going from 2 attacks per second to 1.5. So, you need a number that multiplied by 2 gives you 1.5. That's 0.75.
  • These are actually the "speeds" of your inventory and weapon more than the encumbrance (because the higher you get, the faster you are). You could get the encumbrance by simply using 1 - speed. In this case 1 - 0.75 = 0.25
  • A first, basic formula would than be (1 - inventory_speed) * (1 - weapon_speed) * basic_attack_speed.

Until now, with the slowest values, you'd get (1 - 0.25) * (1 - 0.50) * 2 = 0.375 attacks per second.

  • Now, if you have strength such that the encumbrance is reduced (which means: the speed is increased), you can apply that before the formula, and use the new speed/encumbrance values in the formula.
  • So, you first apply the strength bonus by reducing encumbrance (increasing speed), then you use the above formula.
  • Same idea: what's the highest bonus you can get?

Repeat for agility, and you'll have your formula in no time.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the tips! I ended up using TGonzo´s answer, but yours was very helpful as well \$\endgroup\$ – Adam Gerthel Jan 22 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.