I’m having some problems trying to increase the difficulty of my game.
The games main objective is clicking different objects falling across the screen, before they fall out of your screen, if you click it you gain a point and if you miss it you lose one.
There are currently 3 difficulty factors in the game :
- The speed of the objects, aka how fast they will be falling.
- The size of the objects, the smaller the harder they are to hit.
- How much time there is between each object spawn.
So, let’s start off with the object speed code, currently the speed is too slow at the beginning of the game and it increases way too fast.
The speed should get higher depending on how long you have played the current round.
Here’s my current code :
instantiatedObject.GetComponent<Rigidbody2D>().gravityScale = (float)(0.2 * (timeSinceStart *
difficultyMultiplier) * instantiatedObject.GetComponent<Rigidbody2D>().gravityScale);
The timeSinceStart is the time that has passed since the current round/match started, it gets increased by deltaTime every frame.
difficultyMultiplier is just a number which I use to adjust the difficulty, it’s currently set to 0.25.
Now, let’s move on to the scaling of the objects.
I want the objects to be pretty big in the beginning, and get smaller as the current rounds time progresses.
Currently the objects start waaay too big, and they get small too fast.
Her’es the current code for doing that :
Vector2 newScale = new Vector2();
newScale.x = (float)(3f / (timeSinceStart / difficultyMultiplier) / instantiatedObject.transform.localScale.x * 5);
newScale.y = (float)(3f / (timeSinceStart / difficultyMultiplier) / instantiatedObject.transform.localScale.y * 5);
instantiatedObject.transform.localScale = (Vector3)newScale;
The timeSinceStart and difficultyMultiplier variables are the exact same as the other ones, and the 3 in front is to adjust the size from being too big at start, but it doesn’t really work very well.
And now to the object spawning, currently the time is randomized between each spawn.
It’s randomized between a min and max value, which also should get’s smaller as the round time increases.
Currently the objects spawn in waay to quick and it doesn’t really spawn much faster as time passes.
Here’s the current code for that as well :
void SetNextSpawnTimer()
{
float spawnTimerMin = 0.36f;
float spawnTimerMax = 1.36f;
if (timeSinceStart != 0)
{
spawnTimerMin = spawnTimerMin * difficultyMultiplier % (float)timeSinceStart;
spawnTimerMax = spawnTimerMax * difficultyMultiplier % (float)timeSinceStart;
}
Debug.Log("Spawn Timer Minimum : " + spawnTimerMin + " - Maximum : " + spawnTimerMax);
spawnTimer = Random.RandomRange(spawnTimerMin, spawnTimerMax);
timeSinceLastSpawn = spawnTimer;
}
This function gets called after a object has spawned.
The timeSInceStart and difficultyMultiplier are same as before.
I can’t seem to find a way to fix these functions, I have rewritten them several times and can’t seem to find a good way to do it