Damage to base not printing

I’m at the end of the slide for Making A Base and the damage to base is not printing when my enemy collides with the base mesh?


Is the CSGCylinder3D opted into collision? That’s a common pitfall, and the first thing I’d look at.

Also, I’m assuming there’s a print statement in base.take_damage(). It wouldn’t hurt to put another print statement just before that line in the code you’re showing here; there’s a possibility that the Base isn’t in the correct group, but I think that would show some kind of null error.


I’ve just opted the cylinder into collision as you suggested, but it’s still not printing the collision text in the console? Not sure what I’ve got wrong?

Ahh! Two mistakes on my part: I somehow didn’t register what you were doing in your Enemy script when I looked there, and I forgot that I implemented this in a completely different way in my own project.

Your condition for calling take_damage checks whether progress is precisely equal to 1; however, under the hood, progress is an extremely-high-precision float, and it’s actually quite difficult to make it stop at exactly “1.00000…”. This is actually referenced in another post attached to this lecture:

Change your condition from == 1 to something like > 0.99 and it should then work.

For the purposes of easier testing while continuing to build the game, you might actually want to disable collision on the base again so that it doesn’t become an obstacle for your turret projectiles, but you can always decide to change things again later on =)

1 Like

Hey mate, I tried changing the code but it crashed my game, have I written it incorrectly? as soon as the capsule touches the base it crashes and gives that error.

No, this is actually progress; your original issue is solved because that progress ratio condition is now returning true when it’s supposed to. What you’re seeing now is actually the null error I talked about in earlier replies:

It’s possible there’s a different reason of course, but at the end of the day, the script’s reference to the base is broken. Group mismatch (probably just capitalization or a typo) is the most likely reason for that, so I’d check there first.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms