hey everyone
First of all I want to sincerely apologize to everyone who asked for the method used, and i’m sorry i took literally years to respond, I ended up abandoning this project and was inactive on these forums for a long time, that’s way I only just saw your comments.
i dug up the files and below I tried my best to break down my method for doing this, though i still think it’s a rather ugly solution and will probably not work in most cases
also i made it ages ago and i was a lot less knowledgeable in coding and unreal engine in general, but here goes:
the system i was trying to do was a camera that the player holds that can see certain objects that the player can’t see, to achieve that i used a 2nd camera component in the player character with a Render target texture used in a material set to a screen, i attached a video to show the effect below:
to achieve the illusion of the objects only appearing in the camera feed I used the fact that the camera the player is holding is blocking most of their view, thus by creating a box trace from the camera with a set half size i can hide the object when it’s to far to the edge of the screen, making it disappear when the player is looking it from the edge of their view around the camera, by varying the half size based on the object distance I kept the illusion from failing when the player became closer or farther away from the object.
below i attached several screenshots breaking down the blueprint:
here I had 2 objects and needed to check that both are closer than the maximum distance i manually set before
this chooses the object that is within range and set the “distance to object” variable to the distance between it and the camera, the code works by focusing on only one object at a time sort of, because it needs to change the half size depending on the distance, in the level i had the 2 objects placed at 2 different places so that they don’t intersect with each other.
these all then run the box trace and below is what i connected to it:
these connect to the “start” location input and the “orientation” input in the box trace
this takes the location of a point directly infront of the camera by a certain pre-set distance (which is the maximum view distance), this connects to the “End” Input on the box trace
this calculates the half size based on the distance to the object, and below i explain the variables above
the 6 variables on the left are pre-set variables:
- “Farthest Distance For Object Vis” and “Nearest Distance For Object Vis” are distance limits i placed for the object visibility, so the object’s distance from the camera must be between these 2 values for it to become visible.
- “Trace Y Far” and “Trace Z Far” are the value for y and z of the half size input on the box trace that guaranty the object disappears when it’s not in the 2nd camera view, when it’s exactly at the maximum distance mentioned above, I had to manually figure out these values through trial and error.
- “Trace Y Near” and “Trace Z Near” are the same as the above 2 variables but when the object is at minimum distance allowed.
then i can calculate the “Y Value Change Rate” and the “Z Value Change Rate” as above.
these values are all pre set, and the above blueprint is just for explanation.
all the above calculations feed in the box Trace and then check for further extra conditions to then finally check if the object should be visible or not
a close up for the extra conditions. (the distance checks here might be redundant, but i add them to make sure that the objects disappears at these distances)
Below is a video showing the effect: