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 sajoga · Nov 05, 2015 at 12:31 PM · unity 5rotation

Rotating objects around other without rotating itself

Hi,

I'm having a death battle trying to rotate elements around another without rotating itself.

In a hex board, I'm trying to rotate the elements in the radius of an hex. I can do that with the transform.RotateAround() function, but I want to keep the local rotation of the radius object, so they don't flip.

This is what I have now:

     void Update() {
     
             if (pivot != null && selected != null) {
                 Debug.DrawLine((Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition), pivot.transform.position);
 
 float pivotMouse = AngleBetweenTwoPoints((Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition), pivot.transform.position);
                 float pivotSelected = AngleBetweenTwoPoints(selected.transform.position, pivot.transform.position);
                 float difference = pivotMouse - pivotSelected;
 
 Debug.Log ("Angle between pivot and mouse: " + pivotMouse);
                 Debug.Log ("Angle between pivot and selected: " + pivotSelected);
                 Debug.Log ("Diference: " + difference);
 
 for (int i = 0; i < radius.Count; i++) {
     // This is the standard rotate around function, and goes perfectly, but as I said on the question, I don't want to change the local rotation of the object, just move around the pivot square
     radius[i].transform.RotateAround(pivot.transform.position, Vector3.forward, difference);
                 }
             }
         }

Thanks everyone for your help!!

Comment
Add comment · Show 3
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 toromano · Nov 05, 2015 at 06:46 PM 0
Share

Not a fancy way to do it but, you can simply get the rotation before RotateAround and set to the same rotation after RotateAround.

 Quaternion rot = radius[i].rotation ;
      radius[i].transform.RotateAround(pivot.transform.position, Vector3.forward, difference);
 radius[i].rotation = rot;

Hope that helps.

avatar image sajoga toromano · Nov 10, 2015 at 01:05 PM 0
Share

I know what you mean, the problem is that I don't want to modify their local rotation while they are rotating around the center.

The rotation around the center is not inmediate.

avatar image toromano sajoga · Nov 10, 2015 at 01:51 PM 1
Share

Ok. What i suggested is actually doing what you asked for. $$anonymous$$eeps the local rotation unchanged, just rotating (translating) around the pivot . Here is another way to do it:

 for (int i = 0; i < radius.Count; i++)
 {
     Vector3 pivotToRadius = radius[i].transform.position - pivot.transform.position;
     radius[i].transform.position = pivot.transform.position + pivotToRadius * Quaternion.AngleAxis(difference * speed$$anonymous$$ultiplier, Vector3.forward); // speed$$anonymous$$ultiplier will smooth the rotation
 }

1 Reply

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

Answer by sajoga · Nov 10, 2015 at 02:43 PM

I just replied you and found the solution, but thanks anyway!

 for (int i = 0; i < radiusGems.Count; i++) {
 //radiusGems[i].transform.RotateAround(pivotSquare.transform.position, Vector3.forward, angle);
 radiusGems[i].transform.position = RotatePointAroundPivot(radiusGems[i].transform.position,
                                                                           pivotSquare.transform.position,
                                                                           Quaternion.Euler(0, 0, angle));
             }
 
 ....
 
 
 public static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Quaternion angle) {
         return angle * ( point - pivot) + pivot;
     }
 

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 Botcho · Jul 12, 2018 at 05:27 AM 0
Share

Have you considered constantly refreshing the Quaternion.identity of the object?

 //Rotate individual gem
 radiusGems[i].transform.RotateAround(Vector3 point, Vector3.pivot, Quaternion angle);
 //Constantly reset radiusGem[i]'s angle to 0,0,0
 radiusGems[i].transform.rotation = Quaternion.identity;


Not sure how efficient it is to constantly reset the rotation.

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

41 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

Related Questions

Drag - Rotate 0 Answers

it is possible to rotate a texture ? 0 Answers

have enemy try to get in front of player and push them back help 0 Answers

i am trying to rotate my gameobject about x axis and at the same time i am trying to clamp its rotation to some fixed upper and lower limits but i am getting some real wierd output. ? 0 Answers

Flip Rotation of transform when it bounces off a wall 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