Hello!
I am working on a project where if the player character is within a certain distance of an enemy, they gain a stat known as stress. However, it has a few issues and I would like to know what I can do to improve it to work the way I want. What I currently use is displayed below.
The first and biggest issue with this is I cannot figure out how to make the program distinguish the number of enemies. For example, while this current system can detect whenever -an- enemy is nearby, it cannot distinguish if there are two or three nearby. I would like the system to add additional ‘stress levels’ if there is more than one of a nearby enemy.
Secondarily, right now this custom event is plugged into an event tick, so it gives me an additional point for every tick that an enemy is within the distance. How could I set it up so the event is constantly running but I am only given the additional point once per target?
Thank you for taking the the time to look into this.
A suggestion is to use a collision component with overlap events then you can add the Enemies to an array and check its length to find out how many are nearby. If you dont need direct access to the enemies you could simply count them as they enter/leave the collision using an integer.
Do you think you could elaborate more on the array? I have no set up the event so it uses a collision sphere with an OnBeginOverlap, but it still continues to add multiple levels for being near a single enemy and does not appear to detect if there is more than one.
Sorry it took me awhile to get back to you, this forum is alittle tricky to know who replied to which thread so I only just noticed you replied.
Basically this detects if a character has entered the overlap and makes an entry in the array for them making sure its unique. This is why I typically use an array as you dont need additional checks for uniqueness as you can see by duplicating this code the overlap event may fire more than once even for an identical pawn.
I made this code server side so that the array is held there which means if you do need to access it, it wont be available on the client (if youre doing MP). You can still simplify and not use an array if you need something more light weight like only a byte/integer.
1 Like
Thank you so much for responding, this worked amazingly!