Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by big_stoater · Jun 30, 2018 at 07:59 AM · cameraitweencamera followfield of view

Camera field of view issues with lerp, DoTween, iTween etc.

Hi all,

I'm having an issue with smoothly moving the camera field of view in my game that I cannot resolve.

I have a script attached to the camera that follows the player, this checks if the player is within a certain distance to an object, if it is then the field of view zooms in, if it is not within a certain distance then the field of view zooms out.

In my code I have a list of objects and I iterate over each one to check the distance. The code does work, but the more objects I add to the list the less the field of view zooms in or out. I tried math.lerp, DoTween and iTween and I get the same issue with all of them so the issue is with how I've coded it.

Thanks in advance!

Here's my cameraFollow script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using DG.Tweening;
 
 public class CameraFollow : MonoBehaviour
 {
 
     public GameObject player;
 
     private GameObject launchPad;
     private GameObject tnt;
     private Camera cam;
 
 
     public float cameraHeight = 20f;
     public float offsetX = 0;
     public Vector3 pos;
 
     private float targetFOV = 25.0f;
     private float defaultFOV = 40.0f;
     //public float speed = 0.2f;
     public float distanceToBject = 10.0f;
     [SerializeField] float cameraZoomSpeed = 0.5f;
 
     List<GameObject> fovGroup = new List<GameObject>();
 
 
     // Use this for initialization
     void Start()
     {
 
 
         launchPad = GameObject.Find("Launchpad2");
         tnt = GameObject.Find("tnt_low");
         DOTween.SetTweensCapacity(2000, 50);
         cam = Camera.main;
 
 
         fovGroup.Add(launchPad);
         fovGroup.Add(tnt);
 
     }
 
     // Update is called once per frame
     void LateUpdate()
     {
         pos = player.transform.position;
         pos.x += offsetX;
         pos.z += cameraHeight;
         transform.position = pos;
 
         ZoomFOV();
 
     }
 
     private void ZoomFOV()
     {
         foreach (GameObject pickup in fovGroup)
         {
             if (pickup == null)
             {
                 return;
             }
             if (Vector3.Distance(pickup.transform.position, player.transform.position) <= distanceToBject)
             {
                 ZoomCameraIn();
             }
             else
             {
                 ZoomCameraOut();
             }
         }
     }
 
     private void ZoomCameraIn()
     {
         cam.DOFieldOfView(targetFOV, cameraZoomSpeed).SetEase(Ease.OutSine);
     }
 
     private void ZoomCameraOut()
     {
         cam.DOFieldOfView(defaultFOV, cameraZoomSpeed).SetEase(Ease.OutSine);
     }
 
 
 
 
 
 }
 
 
 
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by big_stoater · Jul 01, 2018 at 06:53 AM

got it sorted, didn't realise that the logic in the code was fighting with itself, School boy error!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jenapier · May 30, 2019 at 10:37 AM 0
Share

This was a long time ago but can you elaborate on how you fixed it? I'm finding when I try zoom in with focalLength and Lerp/DoTween it stutters, or doesn't reach the required focalLength

avatar image big_stoater · May 30, 2019 at 01:10 PM 0
Share

Hi,

The issue I had was that it worked with a single object. When I added more than one the logic in the code didn't work as it was trying to zoom in/out on all the objects simultaneously. I think I fixed this by using colliders on the objects ins$$anonymous$$d.

I also had issues with lerp. The camera would never go the the FOV fully. I changed to using DoTween ins$$anonymous$$d worked as expected.

hope that helps!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Smooth camera on moving platform 1 Answer

Check if position is on screen 0 Answers

How to make a camera zoom in on a specific point 1 Answer

Hide gameObjects which are blocking camera's view 1 Answer

Trigger when something enters the Field of View of the Camera 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges