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 LyonGu · May 13, 2014 at 07:53 AM · rotationrotatearound

Rotate around a pivot between two points?

How can I rotate an object like swing?Here is an example: there are three points: A , B and O.O is pivot,now I want to rotate object from A to B ,then B to A ,and repeat this. Thanks! http://www.screencast.com/users/Lyon.Gu/folders/Default/media/75492834-eaeb-40b1-86da-934756fbff50

Comment
Add comment · Show 4
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 robertbu · May 13, 2014 at 07:55 AM 0
Share

Is this like a pendulum where the swing should slow down on either end of the swing, or is like tick/tock where the speed is constant? I assume you are trying to do this with manipulating the transform, not by using a Rigidbody?

avatar image Maerig · May 13, 2014 at 08:07 AM 0
Share

If you do this using three points, it means A and B will need to be at the exact same distance from O. Wouldn't it be easier if you used for instance two points and an angle ?

avatar image LyonGu · May 13, 2014 at 09:24 AM 0
Share

@robertbu ,hi,sir,you're AWESO$$anonymous$$E! You totally understand what I am saying! That is what I mean!Could you tell me any ideas?Thanks!

avatar image LyonGu · May 13, 2014 at 09:28 AM 0
Share

@$$anonymous$$aerig, hi,sir,you're also right!A and B have same distance from O. But sorry ,I am a beginner,I can't understand your advice :D Also thanks!

2 Replies

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

Answer by robertbu · May 13, 2014 at 02:39 PM

There are many ways to approach this problem depending on the details. Here is a simple(r) one. As indicated by @screenname_taken, if you put an empty game object at 'O' and child your object to 'O' you can rotate 'O', avoiding using the complexity of solving this problem with RotateAround().

Here is a script you can put on 'O'. It requires you figure out the rotation. To do that:

  • place an empty game object at 'O'

  • place your object at 'A'

  • child 'A' to 'O'

  • Now rotate 'O' until the object is at 'B'

  • Record the euler angles in the inspector and enter them for 'endRotation'

Note start rotation should be (0,0,0)

 #pragma strict
 var startRotation : Quaternion;
 var endRotation : Quaternion;
 var speed = 15.0;
 
 function Update() {
     var t = (Mathf.Sin(Time.time * speed) + 1.0) / 2.0;
     transform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
 }
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 LyonGu · May 14, 2014 at 02:09 AM 0
Share

@robertbu ,Thank you so much!You give me the right direction!I child my object to an GameObject,then I rotate the GameObject!Yahoo,I get what I want.Thanks!

avatar image
0

Answer by screenname_taken · May 13, 2014 at 09:01 AM

Since i'm more of a hackaround person, i'd make an emtpy object at exactly the same transformation as O. Then parent to that the object i'd want to swing around O, open the animation panel and do a pendulum animation with O. Meaning, i'd rock O back and forth. That would cause the swing to ... swing around O.

There's also rotateAround() or something like that, but in your case you'd need to calculate the swinging motion and smooth it out before feeding it i think.

Comment
Add comment · Show 3 · 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 LyonGu · May 13, 2014 at 09:32 AM 0
Share

Thanks!I think you are right.I had used RotateAround.But I don't know how to reverse it from B to A,and repeat :D

avatar image screenname_taken · May 13, 2014 at 11:08 AM 0
Share

If you are referring to the animation, do it like A goes to B, B goes back to A. Then set the animation as looping from the editor.

avatar image LyonGu · May 14, 2014 at 02:12 AM 0
Share

@screenname_taken ,Thanks! Nice solution!But I wish I could use my own code.Thanks for sharing!

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

22 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

Related Questions

Creating a 3D orbital movement 0 Answers

RotateAround Limitations 2 Answers

Resetting transform's original position and rotation after using transform.rotateAround 1 Answer

Rotate object in the direction where it is going 1 Answer

Using RotatedAround twice 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