Better solution for my slowing trap?


For you to get a quick idea: So you can place down those traps which slow the enemy down.

Here is the code:

It’s probably my 5th version and also the best working one so far. Now I believe the only issue is that sometimes… very rarely… they dont get their speed back when they stepped out of the trap. So its not 100% working. I tried to solve that with the delay at the end of collision, to make sure they are not touching anything else anymore :smiley:

The big problem here is probably the collision and that I dont want to use tick. Since the enemy can be affected by one trap, then if there is a trap just right next to it, he overlapps with the second trap (while still affected by the first one) then at somepoint not affected anymore by the first one but already missed the first checks of the first collision entry.
Here you can see the critical points. If they move right in the middle of them and touching all traps. Or the moment when they just enter the next trap while still touching the last one.

I believe a tick event would make that much easier, but I try to avoid that since they could be many traps, and many enemies effected by them.

Im happy for every suggestion.
Thanks for your time!

I’m not sure what that custom tick thing is or why it needs to be there. Here is what is happening:

  1. Enemy steps in trap
  2. Enemy is slowed
  3. timer is setup and is waiting
  4. enemy leaves the trap
  5. enemy is given full walk speed
  6. the timer just calls again and sets his walk speed to be slow again.

You need to stop your timer. Use “Clear and Invalidate Timer by Handle” You can save the output of your timer to a TimerHandle variable.

Or you can just get rid of the timer. There’s no reason to have a looping timer here from what I can see.

OH you are trying to lerp the slowdown effect.
Don’t do that. Just use a timeline with a lerp. It’s so much better/easier.

I really like using actor components for things like that - think of it as a highly modular temporary (or permanent) buff / debuff system, where one can grant actors an extra ability. In case of a trap, the *ability *would be deducting health over time and remove itself from the affected actor once expired. And you don’t need to Tick or Delay anything - up to you, of course.

Consider the following, we have 3 elements at play:

  • a **Monster **to be affected:

Above: when the monster receives damage, it checks how much health is left and destroys itself if threshold is met.

  • a Trap with a mesh and a collision box:

When the trap overlaps something, we check whether whatever stepped in is already affected by this trap’s effect (I believe you want to avoid multiple traps affecting a single entity). If this kind of trap effect is not affecting the target, we create one.

  • and the **Trap Effect **itself, the aforementioned actor component. This one deals damage over time:;base64

When a trap creates an effect on a Monster, we start the timer. When the timer executes the Damage Event we increase* Trigger Count.* Then we deal *Damage (*set via a variable exposed to the **Trap **in pic 2) to the owner (whoever stepped in). Finally we check how times this trap has bled its target - if the threshold is met, this component will remove itself from the owning actor. If the owner gets destroyed, they will take this component down with them, too.

vid:…94344ba8bb.mp4 [HR][/HR]
The above is a not a full system, of course. It’s an idea that worked well for me and I believe is worth exploring. It’s quite modular, somewhat easy to maintain and, once combined with inheritance and interfaces, gives you a great deal of flexibility.

Hi @roundpitt

Yes thats the most obvious choice and probably one of my first tries (If I understood you correctly). But then you realize you run into trouble when the trap is not repeaditly asking. Why:
Enemy steps into his first slow trap.
Slow trap asks if it shall activate slow on him
Everything works as intended
But then he steps into his second trap while he is still touching the first one as well and thus is still affected)
The second trap then asks, is he already affected? Oh yeah? Well then I dont apply slow.
A few milliseconds later the Enemy **is now no longer touching the first one = **base walk speed is applied again (no slow anymore)
Now he is still walking on the second trap, but the second trap already asked and therefore no new slow is gonna be applied.

Hope this makes more sense now. I tried to show this in the video etc.
Maybe you have some more suggestions? :slight_smile:


Oh hi again :slight_smile: Anything to say about my Tar/Slow Trap 3D asset? haha

I’m still studying your reply!
Some of your post makes absolutely sense to me, for example I made an “Arrow Trap”, so a damage dealing type, kinda like you suggested.
One thing: You mentioned that all of this is obviously not a full system, but that makes me wonder: This “is valid” node in the 2.pic. Is it working on its own? Without further branches etc.? And if its working on its own and checking something, what is is checking? I mean, obvisously if its valid. But what is valid? Haha I am sorry for my gibberish writing.

Regarding pic 3: Thats probably the half I understand the least. I mean…I have ideas on where this could work really nice, on other traps. But for this slowing one I would need to know how long it takes him to cross the trap, right? If I want him to only be slowed while he is touching the trap.
I kinda tried to avoid such thing because it sounds like manually data input :smiley:

I honestly need to study your text a few times more, maybe I just didnt understood the potential for my current issue yet.

Best regards :slight_smile:

How I would do this is when the component begins overlapping then start using your timer on it, but save your timer handle (it’s the only return on the timer) to some variable.

Now, when the component stops overlapping, (there is an event for this) then you simply invalidate and clear the timer handle you saved. You want to do it slowly? That’s find too, just do it when it stops overlapping.

Your main problem is that you started a timer and you never stop it.