Need Some Advice On Interpolation And Enemy Spawning

Hey Guys,

I’m stuck to find a good solution about spawning enemies. Think of it as a tower defense game.

What I’m trying to do is;

  • Create keypoints for enemy types and spawnrates, as
    Wave0 >> Enemy_0 - 1.0
    Wave5 >> Enemy_0 - 0.5 // Enemy_1 - 0.5
    Wave10 >> Enemy_1 - 0.5 // Enemy_2 - 0.5
  • Interpolate these values and spawn enemies so that Wave3 would be Enemy0 - 0.7 // Enemy1 - 0.3

As an extra I would like to interpolate number of enemies for each wave, calculate number of each enemy type for each wave.

I have created a class for keypoints containing following information;

  • (int) Wave number
  • (int) Enemy type[ ]
  • (float) Enemy rate[ ]
  • (int) Number of enemies

and the level would be created with an array of these keypoints. I’m trying to end up with a multidimensional array of int, representing enemy types and waves. I have tried numerous ways to find a good way of achieving it and still trying.

I would really appreciate if you have any tips or advices.

Thanks
Koray

I think you should use Lerp here. Unity - Scripting API: Mathf.Lerp

I didn’t test this code, but it should be smth like this:

Keypoint (int wave_num, Keypoint kp1, Keypoint kp2)
{
float t = (wave_num - kp1) / (kp2.wave_num - kp1.wave_num); //here we want to calculate 
//the "t" for Lerp, this value should be between 0 and 1 and will be used to determine how  
//close the end result will be to the second Lerp value

enemies_number = Mathf.Lerp (kp1.enemies_number , kp2.enemies_number , t);
}

Here we have a custom constructor for Keypoint class which takes the needed wave number and two base keypoints as parameters. Then to calculate enemies_number it interpolates between the base keypoints’ enemies_number by t. T is calculated based on the wave numbers, like you said.