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 /
  • Help Room /
avatar image
0
Question by Egalestrenge · Feb 25, 2016 at 06:39 PM · rotate objectrotatearoundcamera rotationrotate-around

Rotate Around a character World X axis - weird issue

Hello, I'm trying to get the main camera to rotate around the main character in two possible axis: Y and X. Both of them are archieved by the RotateAround() method:

 using UnityEngine;
 using System.Collections;
 
 public class world_camera : MonoBehaviour {
 
     GameObject MC;
     Vector3 MCInitPos, MCFinPos, cameraMCPos;
     public float turnSpeed, thetaAngle;
 
     // Use this for initialization
     void Start () {
 
         MC = GameObject.FindWithTag("Player");
         MCInitPos = MC.transform.position;
         turnSpeed = 20.0F;
         gameObject.transform.LookAt(MC.transform.position);
     
     }
     
     // Update is called once per frame
     void Update () {
 
 
         MC = GameObject.FindWithTag("Player");
         MCFinPos = MC.transform.position; 
 
         cameraMCPos = gameObject.transform.position - MCFinPos;
         thetaAngle = Mathf.Acos(cameraMCPos.y/cameraMCPos.magnitude);
 
         if(Input.GetKey(KeyCode.LeftArrow)){            
             gameObject.transform.RotateAround(MC.transform.position,Vector3.up,turnSpeed*Time.deltaTime);
         }
         else if(Input.GetKey(KeyCode.RightArrow)){
             gameObject.transform.RotateAround(MC.transform.position,Vector3.up,-turnSpeed*Time.deltaTime);
         }
         else if(Input.GetKey(KeyCode.UpArrow)){
             if(thetaAngle>(0.0F+0.02F)){
                 gameObject.transform.RotateAround(MC.transform.position,Vector3.right,turnSpeed*Time.deltaTime);}
         }
         else if(Input.GetKey(KeyCode.DownArrow)){
             if(thetaAngle<(Mathf.PI/2-0.02F)){
                 gameObject.transform.RotateAround(MC.transform.position,Vector3.right,-turnSpeed*Time.deltaTime);}
         }
 
         else if(Input.GetKey(KeyCode.Keypad0)){
             gameObject.transform.Translate(Vector3.forward*turnSpeed*Time.deltaTime);
         }
 
         else if(Input.GetKey(KeyCode.KeypadPeriod)){
             gameObject.transform.Translate(-Vector3.forward*turnSpeed*Time.deltaTime);
         }
 
         gameObject.transform.LookAt(MC.transform.position);
         gameObject.transform.position+=new Vector3((MCFinPos-MCInitPos).x,0,(MCFinPos-MCInitPos).z);
         MCInitPos = MC.transform.position; 
 

The thing is: the Y-axis rotation works fine: it rotates around the main character, but the X-axis rotation is weird, since it performs a rotation around the X-axis, not OVER the main character, but a bit displaced.

It is just like the rotation is performed in another plane that doesn't cross the main character, as it should be if I want an X-rotation over it.

Have you got any thoughts about why is this?

Thank you very much in advance.

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 Egalestrenge · Feb 25, 2016 at 07:33 PM

Ok, never mind, now I've come up with the explanation: of course, if the camera rotates around the Y-axis, then the rotation around the X-axis will be afected, since the X-axis is allways pointing at the world X direction, and hence the rotation will change depending upon the position of the camera (i.e, the rotation plane will be more or less distanciated from the character).

Sorry for the stupid question lol.

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 dancitron1394 · Dec 13, 2016 at 10:22 PM 0
Share

Out of curiosity, how did you end up solving your camera issue? I'm having the same problem and am a bit stumped.

Thanks!

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

59 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

Related Questions

Rotate an object around one of his childs in the self space (not the world space) 2 Answers

Rotate object arround other object, but always facing the camera 1 Answer

Rotatin an object around another object 0 Answers

Rotate object with mouse 0 Answers

Make GameObject rotate around another around random axis but with fixed distance 0 Answers


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