Hitting enemy ai with light

Hello everyone,
Iam trying to do something like in allen wake 2 where the player can shine light in enemys to damage them.

I tried to recreate that effect with a sphere trace and a Interface which get’s called when the enemy was Hit. that kinda works but iam unsure about how to handle If the Player looks away i did Test with timers but that Just feels way to complicated for what iam trying to do.

Any Input would be nice.

UPDATE : If the Player dosent hit the Enemy anymore i need to stop an Niagara effect on the enemy thats why i started using timers

Fire a multisphere trace (Object, or Profile) the same radius as the light cone every tick while the light is on.

Have it only collide with pawns. Loop the result and apply dmg as needed.

1 Like

Dont see why?

Add a cone to the light that matches the … cone … of light, set to hidden in game. Assign collision profile.

Then detect hits/collision as you would with anything else.

Light traves at the speed of light. Try and make that happen over each frame accurately :stuck_out_tongue_winking_eye:

That would also “hit” when enemys are behind walls which i dont want.

the problem i have which i dod not mention in my original post sorry about that when an enemy gets hit an Niagara effect is started which i need to stop when the player dosent hit the enemy aynmore thats why i started using timers.

Also makeing it tick based isnt that a bad idea since the enmy would take more or less damage depending on the framerate?

The best solution i could think of would be to get the light level at the enemy and decide depending on that if he gets hit by the player but from what i read thats even more complicated.

It wouldnt, you get a hierarchy of what is hit by the sweep.
Just like a line trace knows if it has hit sonething else beforehand…

The engine does not (did not? Maybe lumen added something) support reading light levels.

Best solution you have is direct traces to different bones to estimate a percentage of hits.
Essentially loop enemy bones, line trace to bone loc.
If out of 10 bones you have 10 hits you know the enemy is in full light.

Its main gameplay, so it shouldnt matter how much it costs - within reason.

You could combine the 3 and do the bones returned by the sweep of the light cone only - which ends up allowing you to “scan” a lot more objects.
But it also has its issues if you encounter a meta human and have to wait a cpu lifetime for a billion bones to process…
The obvious solution wouls be to only allow certain skeletons that are approved to function with the functionality.

2 Likes

So i think i got it working now thats what i have

could be improved for sure but it works for now

thank you everyone for helping me !