Out of Combat Regen

Following along with the Fighter, Fighter Target scripts that we made in the Combat portion of the course, where would be a good spot to look at to figure out how to do out of combat health regeneration (and maybe have mana regen faster out of combat)?

Would we put a bool in “Attack” or “Stop Attack” functions?

I want to be able to find a state that we are in combat, and use that to manipulate the regens (and maybe have UI windows close when you’re in combat or, like, have the screen flash red around the borders if you’re in UI and getting attacked)

Probably wait for some other replies, since im just a student of the RPG too xD

With my limited knowledge;
you could probably make a list on the player, where an enemy gets added once you aggro it,
and remove it on death, then if the list is empty, youre not in combat.

Or simply some int, that when the player aggro the enemy,
it calls a method to +1, and on death -1, if its 0 you’re out of combat.

All the AI already look for the player in Awake, so you could like;
make it call a method on the player from AIcontroller in the IsAggrevated() method.
and then when it dies from the Health Class > Die method.

Probably the best way to do this is to make a one way communication between Fighter and Health…

First, in Health

bool inCombat;
public void SetInCombat(bool state)
{
    inCombat=state;
}

Then in Update, only regen health when inCombat is false

Then in Fighter:

void Update()
{
     GetComponent<Health>().SetInCombat(target!=null);

Now this should prevent Health from regenning when the Fighter has a target.

1 Like

To help anyone who wants to do this as well, I’m gonna post my scripts to get it to work…
So what I did was…

in Health.cs, I kind of copied the mana.cs regeneration that we did. I set up a health regen rate in BaseStats, and created these two functions (using your SetInCombat)

public void SetInCombat(bool state)
        {
            inCombat = state;
        }

public float GetRegenRate()
        {
            return GetComponent<BaseStats>().GetStat(Stat.HealthRegenRate);
        }

And in health’s update function I did:

private void Update()
        {
            if(inCombat == false && isDead == false)
            {
                if(healthPts.value < GetMaxHealthPts())
                {
                    healthPts.value += GetRegenRate() * Time.deltaTime;
                }

                if(healthPts.value > GetMaxHealthPts())
                {
                    healthPts.value = GetMaxHealthPts(); 
                }
            }
        }

Then I went over to the Fighter script, and put in your Set in combat line, but it was still not working. Took a look at the script instead of blindly throwing things into update, I moved your line up to the top of update (because if the target is null or dead, we return) so that the line actually runs!

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

Privacy & Terms