Search Unity

Free camera with zoom, panoramic and rotation around a target

Discussion in 'Scripting' started by gbv30, Jul 6, 2015.

  1. gbv30

    gbv30

    Joined:
    Apr 15, 2015
    Posts:
    11
    Hello,

    I recently used a script which rotates, zoom in and zoom out around a target. Unfortunately, I haven't retrieved this script and all the camera scripts I've found (standard assets or others) only include the rotation.
    Does somebody has a link or a script available which would infinitely rotate and zoom around a target?

    Thank you to you!
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Might I ask why you're not trying to create such a script yourself? It's not really hard, and I'm sure you'll learn a few things along the way, rather than just with using a premade script.
     
  3. gbv30

    gbv30

    Joined:
    Apr 15, 2015
    Posts:
    11
    Yes, I understand your question. But I lack time and I already used one which did perfectly the job. So, I prefer using what is already functional.
     
  4. bigboybifdick

    bigboybifdick

    Joined:
    Feb 8, 2014
    Posts:
    60
    Hey,

    Here is a script i just wrote for you, hope it helps.
    FYI, it took me 20 minutes and i consider myself to be a beginner at C#.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Camera_Rotate_Zoom : MonoBehaviour {
    5.  
    6.     // Camera Target
    7.     public GameObject Target;
    8.  
    9.     // Axis for rotation
    10.     public int Axis_X;
    11.     public int Axis_Y;
    12.     public int Axis_Z;
    13.  
    14.     public int SpeedRotation;
    15.    
    16.     // How ZoomedOut and In you want your FOV
    17.     public int FOV_ZoomIn;
    18.     public int FOV_ZoomOut;
    19.  
    20.     // Speed of the zoom : float Between 0 and 1
    21.     public float SpeedZoom;
    22.     public int TimeBetweenZooms;
    23.  
    24.     private bool IsZoomed = false;
    25.  
    26.     IEnumerator ZoomingIn(){
    27.         Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, FOV_ZoomIn, SpeedZoom);
    28.         yield return new WaitForSeconds(TimeBetweenZooms);
    29.         IsZoomed = true;
    30.         Debug.Log("Zoom IN");
    31.     }
    32.  
    33.     IEnumerator ZoomingOut(){
    34.         Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, FOV_ZoomOut, SpeedZoom);
    35.         yield return new WaitForSeconds(TimeBetweenZooms);
    36.         IsZoomed = false;
    37.         Debug.Log("Zoom OUT");
    38.     }
    39.    
    40.     // Update is called once per frame
    41.     void Update () {
    42.         transform.RotateAround (Target.transform.position,new Vector3(Axis_X, Axis_Y, Axis_Z),SpeedRotation );
    43.         Debug.Log(Vector3.Distance (transform.position, Target.transform.position));
    44.  
    45.    
    46.         if(IsZoomed == false){
    47.             StartCoroutine("ZoomingIn");
    48.             Debug.Log("Zoom IN");
    49.         } else if(IsZoomed == true){
    50.             StartCoroutine("ZoomingOut");
    51.             Debug.Log("Zoom OUT");
    52.         }
    53.     }
    54. }
    55.  
     
  5. gbv30

    gbv30

    Joined:
    Apr 15, 2015
    Posts:
    11
    Thank you for your help!
    Here is an other script which works fine as well

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NouveauSmoothFollow : MonoBehaviour
    5. {
    6.     Vector3 randomRotation;
    7.     Vector3 randomModRotation;
    8.    
    9.     void Start()
    10.     {
    11.         randomRotation = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f));
    12.         randomRotation = Vector3.Normalize(randomRotation);
    13.         randomModRotation = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f));
    14.         randomModRotation = Vector3.Normalize(randomModRotation);
    15.     }
    16.    
    17.     void Update()
    18.     {
    19.         float orbitDistance = 10.0f + (Mathf.Pow(Mathf.Cos(Time.time * 3.14159265f / 15.0f) * 0.5f + 0.5f, 3.0f)) * 35.0f;
    20.         //orbitDistance = 30.0f;
    21.        
    22.         Vector3 pos = Quaternion.Euler(randomRotation * Time.time * 25.0f) * (Vector3.up * orbitDistance);
    23.         transform.position = pos;
    24.         transform.LookAt(Vector3.zero);
    25.     }
    26. }
    27.