1
\$\begingroup\$

I am creating endless running game. I want to zoom camera when player dies to the player. I have tried using camera.FieldOfView, but it does not work. Is there another way to zoom In camera to the object when particular condition becomes true. Thanks in advance.

\$\endgroup\$
2
  • \$\begingroup\$ For the trick you can use smooth camera follow when your player dies \$\endgroup\$ Commented Feb 23, 2016 at 6:20
  • \$\begingroup\$ can you explain further? \$\endgroup\$ Commented Feb 23, 2016 at 6:23

1 Answer 1

4
\$\begingroup\$

As I said the trick you can use is to just activate Smooth Camera Follow when your player dies. You can take the script for Smooth Follow from this answer.

Now,

  • Attach it to camera.
  • Play and properly configure it, as you want.
  • Disable the script.
  • Enable it when your player dies.

Note: This is for 3D environment, as you are trying to change FOV of camera, which is applicable in perspective view. If you are developing a 2D game then let me know.

Update: As you already have camera follow script for your 2D game, just change the Camera.main.orthographicSize.

Camera.main.orthographicSize = 1;

You can also make a coroutine for some smooth effect

IEnumerator ZoomIn ()
    {
        while (Camera.main.orthographicSize > 1) {
            yield return new WaitForSeconds (0.01f);
            Camera.main.orthographicSize -= 0.1f;
        }
    }

Just call StartCoroutine ("ZoomIn"); once when your player dies.

\$\endgroup\$
7
  • \$\begingroup\$ Then FOV is obviously not gonna work :) I'm outside for a break, give me 10 minutes:) \$\endgroup\$ Commented Feb 23, 2016 at 6:41
  • \$\begingroup\$ Wait a minute, of you are developing an endless runner then you already must have a camera follow script? Right? \$\endgroup\$ Commented Feb 23, 2016 at 6:43
  • \$\begingroup\$ Then change the size attribute instead of field of view \$\endgroup\$ Commented Feb 23, 2016 at 6:48
  • \$\begingroup\$ orthographicSize?? \$\endgroup\$ Commented Feb 23, 2016 at 6:51
  • 1
    \$\begingroup\$ This made me laugh. \$\endgroup\$
    – jgallant
    Commented Feb 23, 2016 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .