When Player see Enemy inside camera

Dears
I want you support please cause i took 3 days to figure out how i achieve it.
When player see enemy inside his camera it will play sound like ( impact sound effect ).
I it’s work with single line trace, but this is not what i want .
for example the enemy appear behind player, when player rotate his camera to see what behind him and see the enemy it will play sound effect .

I need camera full range not with single line trace .

Please help me to achieve this

Here screen shot with single line trace

Remainder Please help

Anyone , need help Please still can’t figure it out

I’m not sure how to do this in blueprint. I’m sure you can get onscreen or rendered actors, but I dont think theres a node for it.

the easiest way would be to make a giant collision box in front of the camera thats attached to an element that moves with the view. Create an Onbegin Overlap event, drag out “get all overlapping actors”, if it == the actor in question then do once → play the sound. Might work in BP.
Try it out.

Thanks for the answer , I’m thinking also this idea and i think it will work 100%
but this idea will not work for other thing , for example :
If the wall between player and enemy , if i put your idea the sound will play cause the enemy will overlapping
What i need , i need hit actor only camera view this will be work not single line trace , but how to do this ?
I hope to get the answer.

I understand.

You could still use the overlap, but when it overlaps the actor just before playing the sound, do a single line trace to the vector of the actor that gets overlapped if it hits the actor make sound. If it doesnt… it must be behind a wall or obstruction.

otherwise maybe a large sphere trace on event tick

I would have suggested the same as @thankstipscom . You could simply do an LineTrace whenever you get a overlap to check if you can actually see the object.

Then I stumbled over this in the docs, I think it’s exactly what you need:
Shape Traces

OK I will try , and i will be back to give you result , thanks

Hi @thankstipscom and @
I finally manged how to make box line trace and finally detect enemy

, but there is one problem , i tried many way how can’t detect enemy if player see wall .
for example there is wall between enemy and player , i want to block wall and can’t box trace go through it

Here what i’m looking for :

Hello TakeTimeGames,

I went ahead and made a quick example of one way you could use a single line trace to determine if you can see an object. This example should give you a starting point. I hope that this information helps.

Example:

In short this uses a single line trace to form a grid that’s size is determined by the bound of the object you are looking for. This is done by preforming a line trace starting the top of your screen to the top of the object and lerping to a line trace from the bottom of your screen to the bottom of the object. Each time this line trace completes a lerp it will move from side to side one step at a time and perform the vertical sweep again.

The second part of this blueprint checks to see if the object is roughly within the frustum of the camera. It does this by converting the location of the object to screen space and then it checks to see if that screen space location is on screen.

The final check looks to see if the object is within the viewport and if one of the line traces have hit the object that you are looking for. If this returns true then the object can be seen.

Make it a great day

Wow, in BP I woulda when with an easier probably less reliable approach until I was production ready and then did it some better way,but I’m gonna save this image for future use.
thx

Hm, Sounds like you need to do a line trace with the Trace Channel = Visibilty set.

Can you please mr.Rudy send me a copy of your blueprint cause you know it’s very complicated , i got confused :frowning:

Hello TakeTimeGames,

I have recreated the blueprint above in a blank project. I hope that this helps. I have provided the project below. Please remember that this is meant as an example to point you in the correct direction.

link text

Make it a great day

1 Like

Hi Rudy :
your blueorunt it’s working with my idea and thank you for that , but i have problem
if actor in world it’s work , but how about spawn actor?
I mean if the actor not in level , it will be drop frame , cause my actor not in the level
but if i spawn actor it will be work
how avoid dropframe if my actor not spawn

This is Video Example

Thank you for supporting !!

If you are having an issue with the with the actor not being in the level, I would suggest not starting the blueprint on begin play and instead having it start the loop when the actor is spawned and stop the loop if the actor is removed.