Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
This question was closed Dec 15, 2016 at 04:01 AM by dancitron1394 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by dancitron1394 · Dec 13, 2016 at 10:39 PM · camera-movementcamera rotate

Rotate Around Function not working as intended

Hi,

So I'm making a space game, with the camera using the "Rotate Around" function. For the keys that go "left and right" the function works as intended. My camera will rotate around the ship either in a left or right direction. The up and down is what is giving me trouble.

When I am directly behind the ship or in front of it, up and down will take me over/under the ship (as intended). My problem is when I am look at the ship from the port of starboard sides. When I'm in that position the camera will not rotate over or under the ship, but in a circular motion will staying in the relatively same spot (camera will flip over).

I've spent a decent amount of time searching for the answer, and can't seem to find it. Can anyone help me out?

 if (Input.GetKey ("left")) { //left
             transform.RotateAround (playerObject.transform.position, Vector3.up, camRotateSpeed * Time.deltaTime);
 
 
         }
         if (Input.GetKey ("right")) { //right
             transform.RotateAround (playerObject.transform.position, Vector3.down, camRotateSpeed * Time.deltaTime);
 
         }
 
         if (Input.GetKey ("up")) { //up
             
             transform.RotateAround (playerObject.transform.localPosition, Vector3.left, camRotateSpeed * Time.deltaTime);
 
         }
         if (Input.GetKey ("down")) { //right
             transform.RotateAround(playerObject.transform.localPosition, Vector3.right, camRotateSpeed * Time.deltaTime);
 
         }
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

  • Sort: 
avatar image
2
Best Answer

Answer by Irnal · Dec 14, 2016 at 01:14 AM

Hi there,

The issue in your code is that the Global axis vector.up or vector.down stays the same relatively to the camera, as it is the vertical axis but regarding vector.left and vector.right it is not. As your camera moves around your playerObject (in vector.left/right axis), it changes the relative angle it has with the Global vector.left/right axis, because it doesn't share the same 'left' and 'right' with the world space. If you've noticed, when you move up or down you can see that camera's Z rotation is changing too.

So what you need for your axis is to be camera's left/right axis and not the world's. Here is the modification:

 if (Input.GetKey("left"))
         { //left
             transform.RotateAround(playerObject.transform.position, Vector3.up, camRotateSpeed * Time.deltaTime);
 
         }
         if (Input.GetKey("right"))
         { //right
             transform.RotateAround(playerObject.transform.position, Vector3.down, camRotateSpeed * Time.deltaTime);
 
         }
 
         if (Input.GetKey("up"))
         { //up
 
             transform.RotateAround(playerObject.transform.localPosition, -transform.right, camRotateSpeed * Time.deltaTime); // Modified Line
 
         }
         if (Input.GetKey("down"))
         { //down
             transform.RotateAround(playerObject.transform.localPosition, transform.right, camRotateSpeed * Time.deltaTime); // Modified Line
 
         }

Note: I just noticed that there is not transform.left (or down) so you have to type a minus (-) on the transform.right as i did to have the opposite direction.

I hope this is what you were looking for.

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 15, 2016 at 04:00 AM 0
Share

That works great! Thank you for the info/detailed response.

Follow this Question

Answers Answers and Comments

85 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 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

I want to make the player move in the same direction that the camera moves 0 Answers

Roll a ball camera rotation on Q and E 0 Answers

How can i move the player to the direction that the camera points? 2 Answers

getting Jittery movement on camera when player rotating and moving in same time 0 Answers

When attaching my custom camera script camera shakes when player starts to move fast. 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