Search Unity

Camera Rotation Arround Sphere

Discussion in 'Scripting' started by Paykoman, Oct 21, 2016.

  1. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Hi guys, anyone can help with a best way to achieve a camera rotation arround a sphere like the center of the sphere is the pivit point of rotation (rotation with left mouse button) and can zoom with scrool wheel? I normally just work with camera follow character or 3rd person but not with fix center point as rotation, ty
     
  2. Endalth

    Endalth

    Joined:
    Oct 13, 2016
    Posts:
    11
    Check out the youtube channel called Renaissance Coders. The video name is "Unity3D Camera Controllers - Top Down Part 2".
     
    Paykoman likes this.
  3. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Very cool, só if o understand i just hv to target sphere instead of player for camera Work orbitally arround the sphere right? Nice channel :) ty m8
     
  4. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    I ask a wrong question here :( wt i want is to rotate the sphere in the 3 axes by a fix camera perspective something like in this video... Sry for my mystake, but the video u said is good too for other project..



    Appreciate
     
  5. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    After a quick analyze of the video it seems that i need 2 scripts, one in the camera to zoom in and out and another in the sphere to control the rotation.. Can anyone confirm me that plz? Im too newbie yet lol. Cuz the zoom part i can handle easly but the rotation part i only cant get it to rotate left and right and i need it to rotate all directions based on the center point of the sphere...

    My script right now that rotate only left and right
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RotateOrbit : MonoBehaviour
    5. {
    6.     public float speed = 10.0f;
    7.     private Bounds bound;
    8.  
    9.     // Use this for initialization
    10.     void Start ()
    11.     {
    12.         var collider = gameObject.GetComponent<SphereCollider> ();
    13.         if(collider == null)
    14.         {
    15.             collider = gameObject.AddComponent<SphereCollider>();
    16.             Debug.Log ("No collider is detected");
    17.         }
    18.  
    19.         bound = collider.bounds;
    20.         Debug.Log ("Collider Size : " + bound.size.ToString ());
    21.         Debug.Log ("Collider Center: " + bound.center.ToString ());
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void Update ()
    26.     {
    27.         if (Input.GetMouseButtonDown (1))
    28.         {
    29.             if (bound.size.magnitude > 0)
    30.             {
    31.                 var dtx = Input.GetAxis ("Mouse X") * speed;
    32.                 var dty = Input.GetAxis ("Mouse Y") * speed;
    33.                 var pivot = bound.center;
    34.  
    35.                 transform.RotateAround (pivot, Vector3.up, dtx);
    36.                 transform.RotateAround (pivot, Vector3.right, dty);
    37.             }
    38.         }
    39.     }
    40. }
    Appreciate any kind of info, help...
     
    Last edited: Oct 22, 2016
  6. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
  7. faheemmoolla

    faheemmoolla

    Joined:
    Jul 5, 2018
    Posts:
    1
    Paykoman, did you manage to find a solution for this? working on a project that needs it and would highly appreciate it!