Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Follow Orbit Camera

Discussion in 'Scripting' started by RedOneDigitals, Sep 26, 2013.

  1. RedOneDigitals

    RedOneDigitals

    Joined:
    Jan 12, 2013
    Posts:
    3

    Hi! Can you guys help me with some tutorials or samples to start scripting my own Third person follow camera that orbit on X and Y of the mouse input.. i failed to do it with myself. :(

    Please help me!:)
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    There are standard ones that come with unity in the camera-controller package (I think its the camera controller package).


    On a side note, don't override default fonts in threads for no reason... especially with such a terrible one.
     
  3. RedOneDigitals

    RedOneDigitals

    Joined:
    Jan 12, 2013
    Posts:
    3
    Well. :p I know about standard ones that come with unity but i looking for tutorials about making your own camera script from scratch. Thanks for note
     
  4. WorldArchitect

    WorldArchitect

    Joined:
    Sep 27, 2013
    Posts:
    2
  5. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    188
    Try this.

    Code (csharp):
    1.  
    2.  
    3. public Transform target;
    4.  
    5. float xAxis;
    6. float yAxis;
    7.  
    8. const float distance = 10.0f;
    9. const float speed = 5.0f;
    10.  
    11. void Update {
    12.  
    13.     xAxis += Input.GetAxis("Mouse X") * speed;
    14.     yAxis  -= Input.GetAxis("Mouse Y") * speed;
    15.  
    16.     Quaternion rotation = Quaternion.Euler(yAxis, xAxis, 0.0f);
    17.  
    18.     transform.rotation = rotation; 
    19.  
    20.     transform.position = target.position + rotation * new Vector3(0.0f, 0.0f, -distance);
    21. }
    22.  
    23.  
     
    Last edited: Sep 29, 2013
  6. WorldArchitect

    WorldArchitect

    Joined:
    Sep 27, 2013
    Posts:
    2
    ^That doesn't work.

    This does:
    Code (csharp):
    1.     public GameObject target;
    2.     float radius = 3f, angleX = 0f, angleY = -45f;
    3.    
    4.     void Update()
    5.     {
    6.         radius -= Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * 100f;
    7.         angleX += Input.GetAxis("Mouse X") * Time.deltaTime;
    8.         angleY += Input.GetAxis("Mouse Y") * Time.deltaTime;
    9.  
    10.         float x = radius * Mathf.Cos(angleX) * Mathf.Sin(angleY);
    11.         float z = radius * Mathf.Sin(angleX) * Mathf.Sin(angleY);
    12.         float y = radius * Mathf.Cos(angleY);
    13.         transform.position = new Vector3(x + target.transform.position.x,
    14.                                          y + target.transform.position.y,
    15.                                          z + target.transform.position.z);
    16.         transform.LookAt(target.transform.position);
    17.     }
     
  7. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    188
    Look again.
     
  8. RedOneDigitals

    RedOneDigitals

    Joined:
    Jan 12, 2013
    Posts:
    3
    Thank's alot grizzly WorldArchitect both scripts work , this is exactly what i was looking for! i'll modify it based on my need :)
     
  9. grizzly

    grizzly

    Joined:
    Dec 5, 2012
    Posts:
    188
    Enjoy :)