IncreaseDifficulty Won't Work

So basically the function as created in the lesson doesn’t work. I’m not sure if this gets corrected later, but if you’re confused or struggling to see the speed change this is likely why.

In IncreaseDifficulty Tim is creating a new local variable newSpawnInterval and passing that through. He’s using a public variable spawnInterval and subtracting spawnIntervalDecrease from it. Then he’s assigning that value to newSpawnInterval. Then he’s assigning that value to WaitTime.

The problem is that spawnInterval itself is never changed and newSpawnInterval is recreated every time you use the method.

So the original code starts it at 3 and subtracts 0.1, but it will just restart at 3f - 0.1f every time - because those values never change.

TL;DR: If you want a quick fix, you can do this:

public void IncreaseDifficulty()
	spawnInterval -= spawnIntervalDecrease;
	spawnInterval = Math.Max(spawnInterval, minSpawnInterval);
	enemySpawner.WaitTime = spawnInterval;

This should work properly. Ultimately there’s no reason to use newSpawnInterval because you already have a maxSpawnInterval as an outside value that you can reset to.

Hope this helps!

Final Note: If you’re not sure. You can actually test this by assigning a public variable to the value of newSpawnInterval and then have it print to the screen and update with UpdateUI(). It will always show “2.9” because you’re never actually changing the value.

Hello Shadow64,

What lecture is this for? It seems the tagging system didn’t put this in the correct spot.

It’s for the Discovering Godot course, but maybe that was archived except for LTM?

The lecture is “Increasing Difficulty Over Time”: Increasing Difficulty Over Time |

I’ve added the relevant tags to the thread for context, though that course is listed as ‘discontinued’ internally so I don’t know if or who the assigned TA is.

That said, maybe I can poke @Tim_Ruswick himself for this?

It’s all good. Since it’s discontinued, I guess most people won’t be going through it, but if they ever update it, hopefully this will help correct that issue.

I’ve since finished the course and this aspect does not get corrected from what I saw.

And thanks for making the change. I never altered the tags when I posted so I’m not sure why they didn’t properly attach. Maybe that’s how the discontinued course tags work? Thanks for the fix regardless.

Privacy & Terms