-1

When I searching for zooming in Unity online, all the post I come across so far tell me to change the fieldOfView property of the camera.

But when I tested it in the Unity editor, the scene object goes way back to the horizon when the FOV gets too big,

Snapshot 1

1

Snapshot 2

2

(Sorry about the link, I can't post images yet.)

Even though it managed to duplicate the effect of zooming, the object get too far away to be of any use.

I had tried moving the camera forward and backward, but it turned out to be having the same result as changing the FOV.

I had also tried to put the whole scene into an empty GameObject and change its scales while zooming.

But while it worked as I expected, it messes up in-game mechanics such as distances and such.

I have to change many other things because of it.

Is there any other way to let the objects stay in the middle of the scene while achieve the effect of zooming?

Snapshot 3

3

Thank you very much for your help.

Much appreciated!

Noob002
  • 38
  • 5
  • what about not overdoing it? ^^ And why not simply move the camera forth and back? – derHugo Apr 28 '21 at 07:01
  • @derHugo I tried, it turned out to be same effect as changing the FOV. I also thought about something crazy like make the "whole scene" as a GameObject and changing its scales! Now that's what you called "overdoing" it! ^o^||| – Noob002 Apr 28 '21 at 07:06
  • 1
    But your object still **IS** at the center of the screen .. just very far away ... it's a bit unclear how the result should actually look like ... – derHugo Apr 28 '21 at 18:52
  • @derHugo Sorry for the confusion, please see the edit. – Noob002 Apr 29 '21 at 04:25
  • Somebody PLEASE close this question for me! I can not delete it because somebody had already answered it. And I do not know how to make my question better by making it more clearer or something. So somebody please be so kind and shut it down for me, thank you very much! – Noob002 Apr 29 '21 at 11:10
  • 1
    Can you include an image of what you are trying to achieve and what you do not want? A mockup or sketch would be helpful. Unfortunately "zoom" is exactly what people have answered already - move the camera closer, change the field of view - and that's obviously not what you want. – Chris Masterton Apr 30 '21 at 22:56

1 Answers1

1

There's so many ways to do this. To limit the zoom to a certain value you can use Range.

[Range(42f,100f)]
public float zoom;

Then you can you can wire your fieldOfView to your zoom value in Update().

private void Update()
{
    Camera.main.fieldOfView = zoom;
}

If you want your camera to zoom only in a fix target you can use:

Camera.main.transform.LookAt(player, Vector3.up);
Art Zolina III
  • 497
  • 4
  • 10
  • Thank you very much for your answering, but I think you had misunderstood my question. The problem is not whether the FOV is clamped or not, it's that everything in the scene will move back to the horizon while the FOV get bigger. Which is not what I want. I would like it to "stay in the center of the scene" no matter how much you zoomed. – Noob002 Apr 28 '21 at 07:57
  • you mean you want a camera to zoom on a fix target? – Art Zolina III Apr 28 '21 at 08:09
  • @PiggyChu620 What is the problem in moving the camera forward or backward in your scene? don't change `fieldOfView` just change the transform of the camera – Digvijaysinh Gohil Apr 28 '21 at 08:10
  • @ArtZolinaIII I had tried `LookAt`, it still produced the same result - objects moved way back to the horizon. – Noob002 Apr 28 '21 at 08:57
  • @PiggyChu620 try changing the camera projection to orthographic. – Art Zolina III Apr 28 '21 at 09:08
  • @PiggyChu620, Ok I think we have a bit of confusion, Could you tell us what exactly should happen when "Zoom out", the plane should stay at same position but its texture gets Scaled down, or the entire plane should shrink down? – Digvijaysinh Gohil Apr 28 '21 at 10:18
  • @DigvijaysinhGohil Sorry for the confusion, please see the edit. – Noob002 Apr 29 '21 at 04:26
  • @PiggyChu620 change the position of your object to 0,0,0 and also your camera to 0,0,-10 – Art Zolina III Apr 29 '21 at 07:11