I thought about doing damage numbers for a while now — floating damage amount indicators showing the amount of damage enemies receive from various sources. In the end, I decided to do these now — to show player weapon upgrade and mob health progression, show them how much damage weapons do, to show how armor and shields mitigate damage, to make it clear what mobs are “wearing”, and to make awesome animated visual feedback (hopefully).

First, I need to create a place for the damage numbers to live. I will make them part of a new HUD panel for damage numbers. And have a pooled element for the number itself that I can spawn as needed:

Alright, let’s get a basic number displayed:

This is placed in the middle of the screen with no actual logic to it (I literally typed “12” for the label). So I need to add some wires — listen to when enemies take damage and tell the damage numbers system which enemy was hit for how much. And this at least places the right number:

Of course, the number is still not where the mob is, because I don’t have world->screen coordinate conversion logic. If I do that (easier said than done), I get numbers “correctly” placed:

Now the numbers don’t actually follow their target enemy yet, because they were placed once and never updated. In fact, I need them to follow the mob they came from. Which is simple enough, but I did run into an interesting issue that when enemies die, the number would have to stop following the enemy and gets “stuck” on the screen:

It also gets placed at the bottom of the mob, or, technically, their pivot. I need a default offset for:

I need to remember its last position, so I can recalculate where is was supposed to point:

Time to add animation and timing to these, namely duration and vertical float/rise and fade:

And this works out nicely (also, it has been a while since I made gifs):

I do also want a bit of the numbers spreading out in an arc:

And this works out nice too (and follows the mob):

At this point I realized, there is actually a tricky bit with positioning math, because I need to also multiply this by current UI scale — the difference between native camera resolution and the UI scaled resolution. In other words, a compresses and stretched resolution should still properly show the number at the approximately right position:

Unfortunately, I can’t really scale the number of it will lose it’s pixel-perfectness. If it’s a big problem later, I can change the font size or scale it after all. But the actual resolution the game would be played at isn’t that much larger than the default and having smaller numbers on a generally larger monitor is actually fine by me.

Another touch is to have different color for different damage ways:

I considered doing these by type or by source or by some combination. But I went with something that actually provides gameplay feedback about enemy health/armor/shields.

This works for armored mobs:

And shielded mobs:

I was debugging why my mob numbers behave weirdly with these the thing I realized is that mobs being hit in all the damage-absorbing options — health, armor, shields with fancy penetrating weapons — means multiple damage numbers and I don’t like this. I rather keep it simple and make the damage less effective, but not piercing or overlapping. I wrote a quick mob debugger so I can select mobs and see what their values are:

So now the numbers truly decrease in the right order:

I will need to tweak the animation and other properties. I chose the font and size pretty much at random, but the values work okayish.

One thing I am changing my mind is whether the numbers should follow the mob or stay where they were spawned. I actually think the second makes more sense. So:

This actually looks much better, I think. Numbers moving with the player doesn’t really make sense, if one tries it out.

I’m still keeping both options though (since I already wrote them anyway and it’s literally a line of code), just in case I change my mind again (which has totally never happened before):

Another feature I thought about doing was combined damage numbers — that is, as long as the player hits the same mob in quick succession, a new number isn’t spawned, but the old one is increased. But that involves tracking mobs, their damage interval, tracking the numbers, then adjusting their expiry somehow. In short, too much work for questionable benefit.

I am also not (yet) adding any numbers to barrels and such — they ought to explode in a few hits at most, so they shouldn’t really need numbers.

I will also have an optional option in options menu to disable these — not everyone likes them.

Well, that’s about it for these. I think this adds quiet a bit of liveliness to the scene and provides some needed visual feedback, if not in-world one (like sparks and smoke and explosions that I still need to do some day.)

MicroRogue DevDiary #97 – Damage numbers
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *