Hello, i’m trying to make a system like Amnesia game, making the character get damaged when looking at the enemy,
i’ve been trying to use line traces but have no idea how to make this work.
what i want to know is what the best way to make that and if line trace is a good option.
Try using “Was Actor Recently Rendered” node. It can show if the enemy is on screen or not.
You can use the was recently rendered node like Tuerer said, but you’d need to iterate over all of the enemies in the level which can get heavy. Any other way would defeat the purpose of using that method over traces. You should be able to do this with line traces. You just need to trace from the actors eye point and check to see of your trace hits an enemy. Theres a node for getting the eye point of an actor or you can trace from the camera location. You’d want to offset your trace by your view distance, and rotate the vector to match your camera rotation. Then you break the hit result and check if it’s an enemy. There are a lot of ways to do this but the simplest way would be to cast to your enemy class. You can also use interfaces, or tags to check if the hit object is an enemy. I can send screenshots later of you need them.
But how do you propose to account for a field of view angle? If UE had something like Cone Trace with arbitrary angle, that would work; but I can’t see how you could use a line trace to see if enemy is in any point of the screen.
You’d need to be more specific regarding how it’s supposed to work:
- looking directly? use a trace
- looking close enough? use dot product
- present on the screen? use dot or recently rendered
Several examples here:
For what op wants a box, sphere or capsule trace is probably good enough. You’re right that a line trace isnt what OP wants and I forgot that op could just run the was recently rendered node inside of the enemy actor so you’re right lol.