About 'Health For Base'!

In this video (objectives)…

  1. Increase the size of our level
  2. Create a mechanism to decrease player health when enemy reaches base

After watching (learning outcomes)…

Create a simple collision-based health system for the player's base.

(Unique Video Reference: 37_RR_CU2)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Great lecture. I love how you are asking us to implement more and more on our own as we go along with the course.

I think I found a slight bug with how damage to the base is calculated in the lecture. The problem is caused from the following code portion from the EnemyMovement script.

    foreach (Waypoint waypoint in path)
    {
        transform.position = waypoint.transform.position;
        yield return new WaitForSeconds(movementPeriod);
    }

Basically, after each iteration of the loop, there’s a delay of movementPeriod before the loop iterates or terminates. However, the OnTriggerEnter method on the PlayerHealth script is called as soon as the enemy reaches the final Waypoint. This means that your health will be decremented before the explosion occurs. Theoretically, your towers could destroy the enemy gameObject in this interval before the explosion occurs, but as the code is currently written, your health would decrement anyways.

It wasn’t noticeable in the lecture because of how fast the enemies were moving. There’s a few ways to fix this issue. One would be to simply move the yield return statement before transform.position is set in the loop. The other would be to calculate the damage in a different way. Basically, in this second method, the enemy would be responsible for making a call to a method that decrements the health.

I tried moving the yield statement before the transform.position line and this didn’t really work for me. However, your second suggestion of having the enemy calling a method to decrease the health at the same time it exploded works great. Thanks for the suggestion.

Privacy & Terms