For war game call of duty used auto refill health system. How can I do it in unreal engine. I don’t want to add health bar. I just want to make that like call of duty.
Have a float variable being your health and after some time without damage simply increase it to your maximum again.
I don’t know exactly how their mechanic works under the hood, maybe you can try searching on google how Call of Duty health system works and they give you lots of details you wont notice unless you study the game or play it a lot, but you can start by doing the basics and adapting to your needs.
- Have a basic health system (Current Health, Health Reduction, Health Gain)
- Implement life regeneration that can be interrupted and restarted (LifeRegenPerSecond, InterruptRegen, RestartRegen, DelayToRestart)
- Whenever you take damage, interrupt the life regen and restarts it after a desired amount of time. Also, you will have to restart the time counter whenever another damage instance is taken.
If shot/damaged/hittraced damage/whatever ->Set BoolCanRegenHealth False -> Retriggerable Delay (Retriggerable Delay set to something like 5 seconds) -> on RetriggerableDelay complete Set BoolCanRegenHealth to True.
In event tick have a sequence with a branch going off into triggering a function called something like FuncRegenHealth.
In FuncRegenHealth at the start: If BoolCanRegenHealth True AND PlayerHealth<100 -> Get PlayerHealth + 10*DeltaTime (Deltatime being set from tick) and then clamped value to be between 0 and 100 -> Set PlayerHealth to the last step we just did.
That will basically have a function that runs only if the player hasn’t been shot/taken damage in the last five seconds, and only run if health is less than 100, and when running add 10health or whatever you want persecond as it was multipled by deltaTime (deltatime being the duration since the last tick, multiplying values by it turns it into PerSecond if called every tick). The clamp is to make sure when we add 10*deltatime to the previous health value of the players health, that it will never exceed 100 (100 in this case being a float or integer representing the players maximum health value.)
And of course somewhere onhit/ondamaged/whatever if players health is <= 0 and player is valid, DoOnce ->Function PlayerDeath/Killscreen/destroy player/whatever/reloadmap from checkpoint. Also it might be important to mention before you ever do anything in tick or call something or whatever, to check to make sure if the actor is still valid before running. Otherwise you’ll get a nice console spam of errors to PendingKill/actor is not valid/etc., which is Epic’s way of telling you the game has already been told to destroy this actor/remove from memory so any further action after being told to be destroyed is just going to lead to a bunch of nullreference errors and possible crashes/buggered code.
Bonus points is you can have a postprocess effect that adds a strong vignette and either tinted red or desaturated color screen with maybe an image overlayed on top of an alpha blood texture. All you have to do is check the players health, say if the players health is inbetween 1 and 50, map clamped to 100 and 0, use that new map clamped range to set the percentage that the postprocess will be mixed in with other postprocesses for the players camera. 50+ being mapped to 0, so the postprocess will be effectively disabled at 50% health or above, any value under 50 will be gradiented to 100% effect until only 1 hp is left, where in case the screen would be completely red/blood visible/etc. When the players health raises back up, the screen effect will gradually and smoothly fade away due to the range clamp mapped tied to effect which is tied to the health.
I’d probably set the maximum blood red effect to be at 100% mapped at a higher value like 10 or 15 however, as chances are the effect will never be seen at 100% unless the player takes damages of 1 all the time. Something to balance between how scary/alert you want the screen to be compared to how much health the player has left, vs how damaging your guns are.
Look into timelines.
They can be used as triggerable tick events, but you can set the speed. So, you can have a timeline have activates when player takes damage.