Need help with making Enemy AI loop damage on an object.

I can’t find a solution to my problem anywhere online and was wondering if someone here can help me?

I made a blueprint script where my AI will go after an object (in my case a piece of cheese, so that’s what I’ll refer to it as), but if it sees the player it will go after them instead and attack. I also have it where if the player breaks the line of sight of the AI for a few seconds, the AI will go back to the cheese. The problem I am encountering is how to make the AI loop damage when it touches the cheese. I have it able to loop and repeat damaging the player just fine, but the same method won’t work on the cheese. I tried a timer method when the AI goes after the object. But that starts before it even touches it. This is the code I have for it so far.

Hey @Platinum7777! Welcome to the forums!

What if you put a collider on the CHEESE object that uses the fire code from the documentation- checking to see if the overlapping actor is “Mouse” but instead of damaging the overlapper (like fire would) you damage self?

Let us know how it goes!

So your AI is supposed to receive damage when approaching the “cheese”? But, why does the AI go to the cheese if they know it will affect them? Perhaps it’s a trap or some sort?

I’m assuming it’s a trap for the AI by the player. If so, you can just create a sphere collision around the “cheese” which checks if the respective particular AI is overlapping. If so, then apply damage otherwise stop the timer.

So it’s the other way around. I want the AI to deal damage to the cheese when it touches it.

Alright, it’s the same thing. Do the check from the “Cheese” actor class to see if the respective AI is overlapping with the class or not. If so, then apply the damage to the overlapping AI.

Made a mockup for you! Hope this helps, don’t be afraid to ask any questions. :slight_smile:

This is all on the CHEESE actor, not the AI. The only thing your AI needs to do is go to the cheese and get in the overlap! :slight_smile:

image

1 Like

Thank you so much for writing this out! I’ll put it in as soon as I can and get back to you with the results

1 Like

Okay, so I implemented the code, and it works for the first bite. But the damage is not looping.




Ah, I didn’t test it. I put the wrong function in this spot.
image

Replace Take Bite Damage with “Bite Timer”. The only thing triggering “Take Bite Damage” should be the Set Timer By function Name. :slight_smile:

It works! Thank you so much! I’ve been stuck on this forever!

1 Like

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