0
\$\begingroup\$

A game that I'm working on in Unity has a diverse set of spells. The player character and NPCs all use an attributes which modify these spells in different ways. Our design is very fluid and the functions that modify these spells are continuously changing. As of now I've been hard coding the modifying function into the spell class itself while leaving different variables open for designers to modify it. Example for amount of missiles fired:

BaseQty + Strength * MissilesPerStrength

Leaving the BaseQty and MissilesPerStrength attribute open in the inspector for designers.

As our game balancing is changing so much I feel as if only leaving certain variables open isn't enough, as I'll have to go back and change the formula itself if required. I've thought about allowing designers to script the function itself, and for the spell class to get the number for (Example) missiles fired by interpreting the script, but I'm not sure how to go about doing this and in my mind it feels a little bit needlessly complicated for the small team that we are. It's not too much of a hassle to go into the class and change the formula, it just feels wrong not to have it separate.

I'm looking for critique and suggestions on my ideas if possible. Thanks for reading.

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

It all depends on how complicated you want to get with your formulas. The formula you listed in the example is a type of Linear function (Linear as in linear algebra where terms are simply added together, not in linear as a line). If you restrict to linear functions, then you can generalize your equation to be like...

y = C0 + C1*term1 + C2*term2 + C3*term3 + ... + CN*termN

In code, you could make an abstract "term" class that contains the coefficient C and requires you to override the logic needed to compute the specific term. You could then add these to a generic array which just computes the sum.

Generalizing to a non-linear function would be exceedingly more difficult and normally revolves around creating a transform that will take you from a non-linear into a linear. I think you could just avoid this class in general and stick to linear functions.

As an aside, if you stick to these linear function you could later apply some fun machine learning optimization algorithms to have the computer decide how to balance your game, but maybe you need to go over to Cross Validated to learn more about that.

| improve this answer | |
\$\endgroup\$

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