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 /
avatar image
0
Question by gp1234567 · Feb 10, 2020 at 01:35 PM · rotaterotatearound

Rotate around obsolete - missing Rotate overloads???

On Unity 2019.3 I get the comment to replace transform.rotatearound with transform.rotate, but I don't think any of the 6 overloads allow me to do the following: Rotate object 1 around object 2 by an angle on the Y-axis only. How would you re-write the following using transform.Rotate?

 obj1.transform.RotateAround(obj2.transform.position, Vector3.up, 90); 


I'm starting to get pretty annoyed with the amount of stuff unity is making obsolete for no seemingly good reason. What was so bad about rotate around?

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
3
Best Answer

Answer by Bunny83 · Feb 11, 2020 at 02:19 AM

Well, RotateAround is not black magic. You can simply create your own method like this:

 public static class TransformExt
 {
     public static void RotateAroundPoint(this Transform aTrans, Vector3 aPoint, Vector3 aAxis, float aAngle)
     {
         var dir = aTrans.position - aPoint;
         var q = Quaternion.AngleAxis(aAngle, aAxis) ;
         aTrans.position = aPoint + q * dir;
         aTrans.rotation = q * aTrans.rotation;
     }
 }

Put that class somewhere in your project and you can use it just like RotateAround. So if you have a Transform called obj1 you can do

 obj1.RotateAroundPoint(obj2.transform.position, Vector3.up, 90);

However keep in mind that any kind of relative rotation of the worldspace position of an object can result in a slight drift over time. I wouldn't recommend using such an approach. Based on your comment you seem to have a really strange approach. Why is your camera / obj2 a child of obj1 if you want to move / rotate obj1 as if it's a child of obj2? Such a strange relationship will cause additional issues with jitter and precision. If you do a single instant 90° rotation it's probably not that of an issue. However it's still a really strange approach.


Since you talk in abstract terms like obj1, obj2 and we don't know the relative orientation of the objects nor the purpose of the rotation we can't really suggest suitable alternatives. We don't play the guessing game here.

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 Bunny83 · Feb 11, 2020 at 02:32 AM 0
Share

ps: I just had a look at the 2019.3 decompiled code and the RotateAround overload you use does not have the Obsolete attribute attached. Only the overloads which do not take a reference point and therefore do the same as Rotate. They essentially just renamed the RotateAround overloads which take an axis and an angle to Rotate. The RotateAround with 3 parameters should still work and is still documented. Here's the method definition in the current reference code and here's the one that has been deprecated

avatar image
0

Answer by Tripleganger · Feb 10, 2020 at 04:23 PM

@gp1234567 When Unity makes something obsolete is generally because there is already a function (or another mean) that does the job for you. In this case, you can child the object you want to rotate to the object you want to be the pivot point, and then rotate the parent object.

If you don't want your parent object to rotate, then make an empty object and repeat.

In any case, RotateAround has been obsolete since... 2013? It does not look like they will replace it any time soon.

Comment
Add comment · Show 2 · 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 gp1234567 · Feb 10, 2020 at 08:25 PM 0
Share

Thanks for the reply Tripleganger. Sadly, obj2 is the main vr camera, which I CANNOT rotate. It's is, however, already a child of obj1. So the only way to actually rotate object 2, is in fact to rotate obj1 around it, which is what I'm using this call for.

Somehow, creating extra objects, parenting them, then rotating them, then unparenting them and, possibly, having to destroy them again, seems a lot of work to replace what is in fact just an already tested and existing calculation? Any better options?

avatar image Tripleganger gp1234567 · Feb 11, 2020 at 01:30 AM 0
Share

No worries. It is a bit extra, but I believe it is worth it.

I have been working on this code. Although it is mostly hard coded, the only thing wrong with it is that it is not smooth. It makes an object interpolate around the position of another object, but as already said, you might need to work on it and make it smooth. There are enough resources online for you to implement it, I have been working on it for more than I could, sorry for this "half-answer".

https://pastebin.com/bZzRYAL1

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

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

How to rotate an object around its 3 axis and translate it on 2 world axis so it looks like its a dice rolling? 3 Answers

What's the function to replace the obsolete RotateAroundLocal ? 1 Answer

Object follow mouse whilst rotating around object. 1 Answer

How can I make the player rotate with the camera so my movement keys don't get messed up because when I do rotate the camera the move keys go in different directions. 0 Answers

Apply torque/force to rotate an object around a fixed point 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