During my free time, just for fun and to learn something new, I am developing a MOBA in UE4.
Before I explain my issue, I want to mention that I followed the suggested courses of UE4 Learning when I started, I also watch a lot of tutorials and guides.
With that said, in my early game development I encountered the following issue:
I created a tower, the idea behind its logic is that, when my character or my soldiers get into its range, the tower will shoot every second until I leave the range.
The detection works since I can get the tower to shoot, but it will shoot only once, it wont loop.
And I can’t figure out why…
Anyone can help me somehow? I would also appreciate any kind of tutorial, guide or document which describes this kind of behavior for me to learn or see from, if anyone has any idea, feel free to share.
Tick is very expensive as it fires every frame. The above code runs once and creates a timer which will fire every second and run the Check and Shoot Event.
It’s helpful to break things like this down into simple steps which you’ve done in your description. So what you want is 3 things.
when target character becomes in range start firing.
Keep firing once every second.
Stop firing when character leaves the range.
The simplest way I can think of to do this is to use a sphere collision with a radius of the range desired. When the character begins to overlap start the firing timer, when the overlap ends stop firing. IF you want to do this with multiple characters then add them to an array on overlap, on end overlap check if anything is still in the array and if not stop the timer. I would setup a custom collision channel for the target/player/enemy or character that you want to be targeted.