Search Unity

Question Spawning damage numbers

Discussion in 'Visual Effect Graph' started by Qriva, Nov 22, 2021.

  1. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    I would like to create floating damage numbers when player hits enemies.
    From what I experienced UI is not the best with moving or animating things plus I don't like it too much, in addition I don't need anything super complex, so I decided to make in VFX graph. I have already vague idea how it can be made, but I would like to get some help to design it well.

    Lets start with features:
    • system must spawn any numbers, it should not be limited to 2 digits for example
    • it is possible to spawn multiple numbers per frame
    • there must be way control size of numbers
    • it can be spawned anywhere and on top of other things
    • numbers should be resolution and distance independent
    • there should be easy way to customize numbers - at least color and texture/font
    • customizable number animation, more than just poping on screen, but also moving up, jump-falling etc...
    • my game does not use fractions or millions ([.] [,] [K]), but someone else reading this might need that in future, so if you take this into account it would be nice bonus
    My thoughts:

    I feel like the hardest part are first two points and to keep it super simple at the same time. The problem with first point is that I can't use single quad to represent any number, longer number need more horizontal space and in theory it is possible to make quad bigger, but that would increase overdraw for no reason, especially large numbers. In this case it sounds like every digit should be separate particle and each of them should be spawned next to each other to form number.

    There must be also way to spawn multiple numbers per frame, so there are two ways:
    1. Using direct link, but in this case c# must control position of all spawned digits and their size
    2. Setting texture pixels trick to sample positions and numbers or reading the buffer
    I thought to use Screen space size node to keep numbers scale, but either way it is hard to determine spacing between them during spawning and if player is moving (changing distance) spacing between number will change. I think this forces me to use single particle per number, but how to adjust it's size? maybe vertex displacement can help here and custom shader with flipbook would render numbers on it. Other way would be to autogenerate mesh with nice UV, but can this be done? Maybe particle strip could do something like this.

    Any help or ideas are welcome.
     
    Last edited: Nov 28, 2021