Hello, I’ve found this BP and implemented in my game. My gun has a sphere collision, and when an actor with the tag ‘enemy’ enters the sphere, it sets a reference to the enemy. I don’t really understand what happens when the enemy leaves the sphere thought.
Anyway, this doesn’t work very well with multiple enemies, the gun fires at the wrong locations. I wanted to do something like this, but make the gun shoot at the nearest enemy close to the gun. Anyone have ideas? Thanks.
Are your enemies actors or components? Where did you get this BP from? What kind of game is it that the gun needs an overlap sphere? Shouldn’t the gun spawn a projectile that has that sphere?
Enemies are actors. I took this from a Tower defense game. So you plant your gun on the ground and as enemies comes near the gun, the gun shoot at it. So if the enemy enters the sphere of the gun, it signals the gun to shoot. However, I’m not making a tower defense game, i’m making a game similar to vampire survivor / brotato, where you control a character holding a gun, and when the enemy gets close to the character/gun, its starting shooting.
Not optimal but could be a start. Instead of Tick, you could run this on a Timer, let’s say 10x per second. This can be further optimised by dynamically adjusting the size of the sphere overlap. If there’s an enemy close by, there’s no need to check for valid targets at the edge of the screen. Some other bits and bobs can be improved.
I using a blueprint where the character just shoot anything close to it. However, I cannot make the projectile work. Do you know how I can make a projectile shoot where the enemy is, given that I know his location? Also, it’s important that the projectile does not stop at where the enemy is, it should pierce the enemy and go through him.
edit: I tried using interp to with a timeline using set actor location, but does not work very well.
Thanks this works! However my projectile is no a sphere, so its shooting sideways… My projectile is like a cone, and the tip should be facing the enemy.
In overlapped components, you chose ‘A enemy’. What if I have several enemies? It only accepts one class, not several. Is there a way that I can choose an actor that has a tag instead?
I’m using a tag. All enemies have the tag ‘enemy’. The function ‘get overlapping actors’ doesn’t involve tags. Is there something like ‘get overlapping actors with tag’ or similar?
It only works if I select ‘enemy’ as a class inside ‘get overlapping actors’. If I select ‘none’ it doesn’t work. Maybe this doesn’t work and I should look into ‘inheritance and target base class’ ?
Hello, first of all thank you a lot Everynone for your answers, it works well to detect the nearest enemy. I’m quite a newbie on unreal and trying to finish my first project. I have one question regarding your solution, my enemies are damaging the player whenever a collision box in front of them overlap the player. The issue is that it seems to consider that the detection sphere is a part of my player and so I take dmg when an enemy enters in this radius. Could you halp me with that please ?