Need Help with Ray Casts

This is the last thing i need to be fixed, so i hope you can help me.

Currently i´m recreating the Slenderman game. For the “On See Event” i decided to use a Line trace shooting off my camera location with a forward vector. If it hits slenderman it counts the horizontal distance and this will possibly, depending on the range add value to a “death variable”.

So far so good, everything works as intended but here´s the problem. If slenderman however stands further away, the chance of my character perfectly “watching him”, means having him in the middle of the screen would maybe last a split second, if even. If the player would realise slenderman is only a threat when perfectly watched it would break the game´s intention obviously. I tried a box collision to cast a bigger line trace, but the problem remains the same. I could make it very large, and would have good results if he´s close (til the point my box trace is larger than my screen), if he´s further away, still the same issue.

So what i would need is my pov of my camera attached to somewhat an angle of my line/box/sphere/whatever traces in order to make it perfectly fit to the screen and scale up over distance. How can i possibly achieve this?

Thanks for your help!

Regards

You could simply use WasRecentlyRendered just note that if you can only see the shadow it will still return true. A trick could be to split slender man into a head and body actor and don’t cast any shadow on the head and use WasRecentlyRendered on it.

Thank you for your answer!

Yes i´ve already tried that but it seems to be buggy. A few times it would appear not to work and for some reason it stops working after like let´s say 1.5-2 seconds. I don´t know why (shooting it off my event tick).

I´ve also tried a dot product but it seemd to only work sometimes aswell.

If the actor is within the view frustum but hidden behind an object it can sometimes still return true. You could fix this with a line of sight trace when recently rendered to make sure it is visible.

i mean i can try it again but that´s what my debugging ended up with. That also seemed to be a deal a few times, but not an actually big issue.

The big issue for me really was, that it´d stop working for some reason after it ran for a good 2 seconds. Also it seemed buggy when i turned back once more on the object (let´s say i see slenderman (it says visible), i turn away (it says not visible), i turn back again and (it still says not visible); (It got hooked up with Event Tick so it should cast often enough to notice the change?!) Any clue what this could be? Once i´m home i´ll retry it, and if it still doesn´t work i´ll post you a video.

I can see that this seems to be the easier solution (if i can make it work), but just out of interest tho, so there´s no way to manipulate the ray cast as i asked for in Post 1?

Thanks for your help in any case!

Nothing stops you from making your own calculations for visibility checking but using what is already there and chasing the “bug” could be quicker.

You would need to recreate the isVisible check by getting a vector from the camera towards slender man and comparing it with the forward vector of the camera. If nothing is blocking the view, and it is within a certain threshold and the length is shorter than the view distance etc. then he is visible. But you need even more checks or even a tiny object will obscure slender man.

ah yes sure thing. Sorry i just thought there might be an easy way to solve this issue (i´m a beginner after all)

So here´s the video of me checking out if has been recently rendered. The blue note comes from a return tree of a cast to slenderman, out on his spawning section. Sorry for the mess. As i said i got quite some attempts trying to fix this.

as you can see at the end of the video. I get a true in return, even tho i´m clearly turning away off him

e: at the end of the video in the very last second you can see i receive a false. I think that is, because the actor is getting destroyed on my blueprint after a couple of seconds. So i guess, to me how it looks like the has recently rendered messes something up with him being spawned at all. Maybe the issue is coming from me taking the return target of cast to slenderman from another blueprint? I don´t really know…