Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by biellls · Feb 19, 2015 at 03:17 PM · camera2drotationcamera rotate

Set camera rotation around point in 2D

I have a game which gets as input the degrees of rotation around the z axis that the game's camera should have. If I want the game to rotate around the center point I can add a script to the camera with the following code.

 Vector3 temp = gameObject.transform.eulerAngle;
 temp.z = inputDegreesOfRotation;
 gameObject.transform.eulerAngles = temp;

However, I don't want the camera to rotate around the center, but around a given point. I'm aware of rotateAround, but it's not what I'm looking for since I don't want to perform a rotation on the camera to get a new euler angle. I already know the angle and just want to set it. What is the best way to do this?

alt text

screen-shot-2015-02-19-at-125849-pm.png (22.6 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

3 Replies

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

Answer by biellls · Feb 20, 2015 at 12:28 PM

Thanks to everyone who answered, but unfortunately none of the previous answers worked correctly on my device. I ended up finding this solution:

 Calculate translation from camera center to pivot point
 Translate camera to pivot point
 Set camera euler angles to zero
 Rotate camera by the given degrees
 Translate camera back to original position (negative of the translation calculated in the first step)
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 hexagonius · Feb 19, 2015 at 07:16 PM

You could use an Empty GameObject to do the job:

  • Set it at where you want the Camera to rotate around

  • Set the camera to where it should be rotated at

  • child it to the empty

  • rotate the empty by your degrees

  • unchild the camera

  • reset the empty for next time.

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 Tuncer · Feb 19, 2015 at 07:28 PM

 public void turnAround (Vector2 point, GameObject obj, float angle)
 {
     Vector3 point3 = new Vector3(point.x,point.y,0);
     Vector3 axis = new Vector3 (0,0,1);
     obj.transform.RotateAround(point3,axis,angle);
 }

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

[Solved :D] Camera auto turns 180° from its init position on Play (Animated GIF Included!) 1 Answer

top down 3d camera rotation question 2 Answers

Reset player movement axes after camera rotation 1 Answer

How to make the skybox pitch up and down with the camera? 0 Answers

Top down camera for object moving on sphere 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