Setting up line tracing with multiple enemies?

Hello all,

I have been making and FPS shooter and have come across a problem.

I have managed to set up line trace detection with one enemy but I can not seem to implement the detection for more enemies? I’m wondering what i can add to my code to do this. Any suggestions are much appreciated.

I have attached screenshots of my code.

TitanfallController is my character controller and ZombieAI is my enemy.

Hi, can you use that system for BP code?

Your screenshots are not readable

Thanks for the reply,

Here is the link blueprintUE | PasteBin For Unreal Engine 4

can you explain your issue a bit more? “I can not seem to implement the detection for more enemies?” do you mean enemies of different classes? if thats the cast then that wont be easy with your current setup, i would suggest you make use of the built in damage system in the engine. look into the apply damage and the event any damage nodes. using those two will make it so you can damage any actor without needing to cast to them. it will require you to setup how the damage is handled on the other end via the event any damage though. this last point can be mitigated however if you use inheritance to have all your characters inherit from a common parent.

Thanks for the suggestion

My issue is that my code for the weapon (as shown in the images) is only able to detect and damage the Zombie AI enemy. I have another enemy I want to implement and be detected by the ray traces but I am not sure how to implement this. Hope that helps

in that case i would use something like the following.

for the weapon i would do your trace then get the hit actor and apply damage. in the example below i checked to make sure there was a hit and made sure it was a character.

then in all your characters you would have a script like the below picture. for this you would use the event any damage which gets incoming damage from the apply damage node. then you take the damage incoming and subtract it from the current health then set health. i also included a little death check.

this all makes it so you dont need a specific reference to damage something. your basically saying i want to apply damage to that thing over there without caring what the thing is. then the thing can decide how to handle the incoming damage. this also makes it easier to implement things like shields.

Many thanks for this!

One small issue, My LineTrace node does not have the options you have in the first image. Is there something I need to do in order to see them?

The options I mean are the out hit hit actor

Just right click the hit pin and select split struct pin. Its basically the same thing as the break node you have in your picture