- Home /
FOV that brings gameObjects close
Hey, guys so I'm working a third persion game and I am in need of a script that brings a game object in view up close to the players realization. It should work similarly to radar where on approaching said gameobject it becomes enlarge into view.
Answer by chrstw · Jul 20, 2016 at 02:27 PM
So FOV stands for Field of View angle, and is a Camera Property. Increasing the FOV will make the view frustum wider, making all objects within the frustum appear smaller. Decreasing the FOV will make the view frustum more narrow, making all objects inside appear larger. Actual positions are not affected, only the amount of screen space they get. Increasing the FOV over time makes the camera seem to Zoom Out, and decreasing makes it Zoom In.
If you need a script that brings a 1 of N objects into view in front of the camera you have a couple of different approaches.
1) Move the Camera to look at the object.
One approach here would be to create a desired transform that looks at the object in question from your desired position. Then have a script that interpolates from the main camera transform to the desired, and when done back to the main.
2) Move the object to be viewed by the camera. Find a desired position in front of the Camera, then either clone the object, or move the actual object to that position and restore game state when done.
Answer by Glurth · Jul 19, 2016 at 11:42 PM
If you start mucking the the FOV you are going to start getting odd effects, like fish-eye, and tunnel vision. I would recommend you leave your FOV alone, and simply place the object the appropriate DISTANCE in front of the camera. I'm not sure I understand what you mean about "approaching it", do you just want to trigger the "examination" when close enough to the object?
Here is how I would bring the object up close for close viewing:
Use the object's Render component, to get it's "Bounds". (The "bounds" defines a box that encloses the entire object) (https://docs.unity3d.com/ScriptReference/Renderer-bounds.html)
Use the bounds to get the "center" of the object (https://docs.unity3d.com/ScriptReference/Bounds-center.html), and put that point directly in front of the camera. at a distance of about 2.0 times the bounds.size.magnitude. (the "2.0 times" may vary depending on just HOW close you want it, and how oblong the object is)
Your answer
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object 1 Answer
GUI controlling other game objects 0 Answers
How can a camera activate an animation 2 Answers
What is my camera rendering? 2 Answers
Raycasting depending on viewport 2 Answers