2

I'm trying to make health reduce while interacting with an object. I'm using Unreal Engine Blueprint. I want it so as soon as you interact with the object your health goes down, but once you stop interacting your health stops reducing.

Here's my blueprint: enter image description here

3 Answers3

1

I would do this in three parts:

  1. On begin overlap, cast the overlapping object to the player pawn and if the cast succeeds, stash the player pawn in a member variable.
  2. Run a repeating timer that deals damage every x seconds to the pawn stashed in the member variable if it's not null.
  3. On end overlap, set the member variable to null.

This way if something other than the player comes in contact with the object, it's ignored, but when the player makes contact it starts repeatedly dealing damage until the player ends contact.

Kevin Mack
  • 1,174
  • 1
  • 9
  • 20
0

make private bool variable in the class. set it to true when begin overlap. set it to false when end overlap.

in Tick function reduce health when variable is true.

to be very simple...

  • 1
    The problem with reducing health on tick rather than on a timer is that players on faster computers will be penalized. Someone with a PC able to run the software at 120fps will take more damage per second than someone only able to run at 30fps. If you do want to decrement health on tick, make sure you multiply the damage you're dealing on tick by the deltatime. – Kevin Mack Oct 07 '21 at 01:41
  • Yes and exactly i didnt tell that deltatime thing cuase i left it to OP, but sure we have to multiply with deltatime to get uniform health decrease across various pc configurations –  Oct 07 '21 at 05:31
0

fallow cpp way and make changes as in Tick function like the person above said ...

make private bool variable in the class. set it to true when begin overlap. set it to false when end overlap.

in Tick function reduce health when variable is true.

enzio91900
  • 41
  • 8