0
\$\begingroup\$

I'm working on a music game. It has genres like pop and rock. Different centuries have different music popularities. (Influences the sales)

I thought about building an object like this:

var rock = {
 0: 0.8,
 2: 1.0,
 5: 0.5,
 10: 0.3
}

So if I am in the year 1.0, the popularity value would be 0.9. Is this the "best" way to do it?

\$\endgroup\$
  • \$\begingroup\$ The "best" depends on your definition of "best". Your method looks fine to me. What specifically is the problem? \$\endgroup\$ – Anko Mar 5 '15 at 10:29
1
\$\begingroup\$

This is a simple example of linear interpolation.

In this formula:

  • timeA and valueA are your first fixpoint
  • timeB and valueB are your second fixpoint
  • timeN and valueN are the point you are looking for

valueN = valueA + (valueB-valueA) * ( (timeN - timeA) / (timeB - timeA) )

When you want a smoother interpolation around your fixpoints, you could go for a more fancy spline interpolation. But the additional complexity is usually only worth it when it is something in direct view of the player and not something they perceive indirectly through another value. It's also very frustrating for players interested in meta-gaming because spline interpolation is a lot harder to grasp than linear interpolation (although this can be an advantage when you want to discourage players from meta-gaming and instead get more immersed in the intended game).

\$\endgroup\$

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.