Continuing on from part 1, I will talk about about what are known in gaming as ‘modifiers’ . They are known by various names like weapon modifiers, armour bonuses, to-hit bonuses, weight penalty, and so on.
Game mechanics, under the hood of most role playing games, involves around defining the ‘final value’ of some object or action. This ‘final value’ is often based on a ‘base value’ which is then translated by a ‘modifier’. These may seem like useless abstractions, but in fact help reduce the complexity of the development of the game, and make it easier to make changes later. All very important when you are a team of one.
So, in picture form:
This is a little vague, but some examples should clarify things…
The base value is a numerical quantity (usually an integer) for something. Things like how much damage a sword does, or a character’s agility, using the examples above. The base value can be a fixed value (like agility) or a randomly generated value (weapon damage can randomly vary between a range of values e.g swords can inflict 1-6 points damage). There are more complex scenarios on how the modifier can affect the base value (like affecting the minimum damage only, or the addition of extra effects like adding poisoning to a sword attack), but I will ignore those for now.
The modifier is an offset value which is applied to the base value, with some sort of mathematical operator (addition ,multiplication, logarithmic, and so on). I will stick to addition for now, because I have a formula for modifier which works well enough for now. In future, the mathematical operators can be expanded to anything required (like multiplication, or go crazy with polynomials).
For now, I have decided on using a single type of equation to create modifiers which are added to the base value. Dredging up long forgotten math lectures from my hindbrain, I am going with what is known as a hyperbolic function ( I started with a hyperbolic sinh function, and took it from there).
I picked this because it an ‘S’ (sigmoid) shaped curve, which means than for most modifiers, only very low or high values make a real difference to the modifier. So using the effect of strength on sword damage as an example, only very high strength will make a big difference to damage, with most values only adding modest benefits. Similarly very low strength significantly reduces damage, as the modifier is negative.
Here is the modifier formula, after a nifty WordPress plugin rendered it for me.
- A is a value of an attribute like agility or strength (between 1 and 20)
- c1, c2, offset, and scale are ‘translation’ factors which move and squeeze the curve around to the values I want. Ignore them for now, unless you are into that sort of thing.
This formula gives a real valued result, which I round up and down to an integer for convenience.
An Example – The Effect of Strength on Weapon Damage
Using the formula with values: c1=1.5, c2=2.2, A = 1 to 20, offset=6, and scale=5
|Strength||Modifier Exact Value||Weapon Damage Modifier|
From the table above, you can see that for most strength values, the effect on weapon damage is modest. By adjusting the parameters, I could do things like:
- flatten the curve even more (so strength plays less of a role on weapon damage)
- increase the maximum values for extreme strength or weakness and so on
- Update this in real time (e.g a spell which reduces the effect of strength)
I have enough now to knock up a demo engine with some monsters fighting it out to the death. I’ll start now.
Update 15th April, 2014: Here is a tiny game which shows the engine in action.