Skip to main content
added 636 characters in body
Source Link
Carlos
  • 236
  • 1
  • 4

In my experience, i prefer to use a single "big" hit every so often than to accumulate a lot of very small differences.

I would recomend you to use a frequency (for the sake of simplicity i'd go with 1 second) and on your update loop check how much time has passed since the last time the dot has applied damage. Once you get to a time where you know damage has to be applied, you apply it, reset the counter and wait for the next tick of the dot.

float dot_frequency = DOT_FREQUENCY;
bool apply_first_tick_immediately = true; //<--With this you control the behavior as you asked

void on_dot_applied()
{
    if (apply_first_tick_immediately)
        time_since_last_tick = dot_frequency;
    else
        time_since_last_tick = 0;
}

void update(float elapsed_time)
{
    time_since_last_tick += elapsed_time;
    time_since_start += elapsed_time;
    if (time_since_last_tick >= 1dot_frequency)
    {
        apply_dot_damage();  // <-- here get your formula for dot damage
        time_since_last_tick -= 1;dot_frequency;
    }
    if (time_since_start >= DOT_DURATION)
    {
        remove_dot();
    }
 }

I hope this helps.

EDIT: Added an example of how you can work with the "deal damage immediately" idea. Probably the on_dot_applied is an event that is called immediately as a dot is applied to setup certain effects of the specific dot, such as a fire particle effect, maybe a shader change.

In my experience, i prefer to use a single "big" hit every so often than to accumulate a lot of very small differences.

I would recomend you to use a frequency (for the sake of simplicity i'd go with 1 second) and on your update loop check how much time has passed since the last time the dot has applied damage. Once you get to a time where you know damage has to be applied, you apply it, reset the counter and wait for the next tick of the dot.

void update(float elapsed_time)
{
    time_since_last_tick += elapsed_time;
    time_since_start += elapsed_time;
    if (time_since_last_tick >= 1)
    {
        apply_dot_damage();  // <-- here get your formula for dot damage
        time_since_last_tick -= 1;
    }
    if (time_since_start >= DOT_DURATION)
    {
        remove_dot();
    }
 }

I hope this helps.

In my experience, i prefer to use a single "big" hit every so often than to accumulate a lot of very small differences.

I would recomend you to use a frequency (for the sake of simplicity i'd go with 1 second) and on your update loop check how much time has passed since the last time the dot has applied damage. Once you get to a time where you know damage has to be applied, you apply it, reset the counter and wait for the next tick of the dot.

float dot_frequency = DOT_FREQUENCY;
bool apply_first_tick_immediately = true; //<--With this you control the behavior as you asked

void on_dot_applied()
{
    if (apply_first_tick_immediately)
        time_since_last_tick = dot_frequency;
    else
        time_since_last_tick = 0;
}

void update(float elapsed_time)
{
    time_since_last_tick += elapsed_time;
    time_since_start += elapsed_time;
    if (time_since_last_tick >= dot_frequency)
    {
        apply_dot_damage();  // <-- here get your formula for dot damage
        time_since_last_tick -= dot_frequency;
    }
    if (time_since_start >= DOT_DURATION)
    {
        remove_dot();
    }
 }

I hope this helps.

EDIT: Added an example of how you can work with the "deal damage immediately" idea. Probably the on_dot_applied is an event that is called immediately as a dot is applied to setup certain effects of the specific dot, such as a fire particle effect, maybe a shader change.

Source Link
Carlos
  • 236
  • 1
  • 4

In my experience, i prefer to use a single "big" hit every so often than to accumulate a lot of very small differences.

I would recomend you to use a frequency (for the sake of simplicity i'd go with 1 second) and on your update loop check how much time has passed since the last time the dot has applied damage. Once you get to a time where you know damage has to be applied, you apply it, reset the counter and wait for the next tick of the dot.

void update(float elapsed_time)
{
    time_since_last_tick += elapsed_time;
    time_since_start += elapsed_time;
    if (time_since_last_tick >= 1)
    {
        apply_dot_damage();  // <-- here get your formula for dot damage
        time_since_last_tick -= 1;
    }
    if (time_since_start >= DOT_DURATION)
    {
        remove_dot();
    }
 }

I hope this helps.