• 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 raycosantana · Aug 12, 2013 at 10:31 PM · cameraorbitpositions

Orbit/Rotate camera through four set positions

I made a simply follow script with a switch to change the position of the camera to any of those four positions but I don't like the result, now I want to make a rotate/Orbit the camera through these four positions, think of this four positions as South, west, east and north of the orbit camera, The regular orbit camera don't suit my needs.

To illustrate the difference I made a comparison image, both camera script have the same angle (45º) and roughly the same distance, yet the orbit camera offers zero visibility in comparison.

alt text

This is my script as of now, those four positions are in the cases I use to change between them, I want to turn this into and orbit camera

 using UnityEngine;
 using System.Collections;
 
 public class cameraFollow : MonoBehaviour {
     public GameObject doke;
     public Vector3 rotationoffset;
     public float offset;
     public float height;
     private int procams = 0;
 
     // Use this for initialization
     
     void Start () {
  
     }
     
     // Update is called once per frame
     void LateUpdate () {
         if (Input.GetButtonDown("Fire2") == true){
             procams += 1;
         }
         switch (procams){
         case 4:
         procams = 0;
         break;
         case 3:
     //westest position
     transform.position = new Vector3 (doke.transform.position.x +offset, doke.transform.position.y + height,doke.transform.position.z );
     transform.localEulerAngles = new Vector3 (rotationoffset.x , 270,rotationoffset.z);
         break;
         case 2:
     //norhtest position
     transform.position = new Vector3 (doke.transform.position.x , doke.transform.position.y + height,doke.transform.position.z +offset);
     transform.localEulerAngles = new Vector3 (rotationoffset.x , 180,rotationoffset.z);
         break;
         case 1:
     //eastest position
     transform.position = new Vector3 (doke.transform.position.x -offset, doke.transform.position.y + height,doke.transform.position.z );
     transform.localEulerAngles = new Vector3 (rotationoffset.x , 90,rotationoffset.z);
         break;
         case 0:
     //southest position
     transform.position = new Vector3 (doke.transform.position.x , doke.transform.position.y + height,doke.transform.position.z -offset);
     transform.localEulerAngles = rotationoffset;
             break;
         }
     }
 }


If you are thinking I could just add offset (like my cam does) to the orbit camera I already tried that, didn't work, the orbit center was displaced.

camdiference.jpg (182.3 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by raycosantana · Aug 12, 2013 at 11:50 PM

Ok, I actually forgot about the follow script and wrote an orbit camera script from scratch to include an Offset value, here it is in case anyone interested

 public Transform target;
 public float distance = 10.0f;
 public float offsetpos = 0.0f;
 public float xSpeed = 250.0f;
 public float ySpeed = 120.0f;
 
 public float yMinLimit = -20;
 public float yMaxLimit = 80;
 
 private float x = 0.0f;
 private float y = 0.0f;
 
 void Start () 
 {
     var angles = transform.eulerAngles;
     x = angles.y;
     y = angles.x;
 
     // Make the rigid body not change rotation
     if (rigidbody) 
         rigidbody.freezeRotation = true;
 }
 
 void LateUpdate () 
 {
     if (target)
     {
         x += Input.GetAxis("Mouse X") * xSpeed * Time.deltaTime;
         y -= Input.GetAxis("Mouse Y") * ySpeed * Time.deltaTime;
 
         y = ClampAngle(y, yMinLimit, yMaxLimit);
 
         transform.rotation = Quaternion.Euler(y, x, 0);
             //transform.position = new Vector3 (x , height, distance);
         transform.position = (Quaternion.Euler(y+offsetpos, x, 0)) * new Vector3(0.0f, 0.0f, -distance) + new Vector3(target.position.x, target.position.y, target.position.z);
     }
 }
 
 static float ClampAngle(float angle, float min, float max) 
 {
     if (angle < -360)
     {
         angle += 360;
     }
     if (angle > 360)
     {
         angle -= 360;
     }
     return Mathf.Clamp(angle, min, max);
 }

}

Comment
Add comment · 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
0

Answer by DaveA · Aug 12, 2013 at 10:52 PM

Could you just make 4 camera game objects, all children of the Player, and only one set 'active' at a time?

Comment
Add comment · Show 1 · 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 raycosantana · Aug 12, 2013 at 11:10 PM 0
Share

How is that gonna help me make an orbit camera? because that would be exactly like what I have right now. I want to make an orbit camera but have the same visibility as the camera I have now.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Getting a scrolling camera to orbit around a circular walkway, following the player? 1 Answer

Camera Orbiting Character: How to make an object move with another with no rotation 1 Answer

3rd person player 0 Answers

help with my orbit camera script 0 Answers

Mouse Orbit + Move Object + Follow Problem 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