0
\$\begingroup\$

I'm working on an astroid mining game where there's the player controlled ship that can split astroids into smaller ore chunks to then collect and bring back to a base station for processing. I'd like to have a percent composition for these astroids that provides a weighted loot drop table for what ores each astroid drops when split by the player. In addition to this, I'd like to be able to shift the weights of the drops in the table based on the distance the player is from the base station. For example:

Near to Base Station IRON - 0.80 SILVER - 0.15 GOLD - 0.05 Far from Base Station IRON - 0.50 SILVER = 0.30 GOLD - 0.20 

It'd be simple to create multiple drop tables with these values preset, however I'd like to interpolate the values and change them relative to the distance the player is from the base station. What would be a good approach to achieving this behavior?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Sounds like you can do exactly what you said: dynamically make a new table by interpolating between the min & max tables.

Example:

double[] nearTable = new double[] { 0.80, 0.15, 0.05 }; double[] farTable = new double[] { 0.50, 0.30, 0.20 }; double minDist = 10; double maxDist = 110; double currDist = 60; if (currDist < minDist) currDist = minDist; if (currDist > maxDist) currDist = maxDist; double percentage = (currDist - minDist) / (maxDist - minDist); double[] table = new double[nearTable.Length]; for (int a = 0; a < table.Length; a++) table[a] = nearTable[a] + (farTable[a] - nearTable[a]) * percentage; 
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think I'd use a Clamp01(percentage) instead of the if statements, or Clamp(percentage, 0, 1) if that shorthand isn't available. \$\endgroup\$ Commented Oct 19, 2022 at 19:25
  • 1
    \$\begingroup\$ Right on, appreciate the advice. This implementation is working and I incorporated the clamp recommendation. \$\endgroup\$ Commented Oct 19, 2022 at 21:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.