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 superme2012 · Aug 05, 2013 at 07:07 PM · objectrotate objectotherby

Rotate One Object by Another, without matching the rotation?

Been trying to work this one out all day, I’m trying to make object A’s rotation affect Objects B’s rotation but without having Object A and Object B to match rotations.

At first I thought, just add the rotation value from A to B, but then noticed it's not that simple ;).

There are two major problems I can see, one: values need to mirror to reverse the rotation direction and two: the rotation value has to be some sort of usable offset, something that is also taking the original rotation into account.

I know there must be some kind of magic function to calculate this but really cant find it.

Been digging through docs and posts all day with no joy.

Comment
Add comment · Show 6
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 perchik · Aug 05, 2013 at 07:10 PM 0
Share

I'm not sure what you're asking. On Object B, you can change its rotation by transform.Rotate . With that in script, you could rotate it by whatever you want, including the value of Object A's rotation.... but I'm not sure what you're asking

avatar image superme2012 · Aug 05, 2013 at 07:20 PM 0
Share

I'm trying to transfer the rotation of one object to the other but only using the amount of rotation applied. Also to do this in a full 360.

I will play some more with "transform.Rotate" maybe there is something I’m missing. Possibly calculate the rotation needed between a $$anonymous$$ and max value.

avatar image perchik · Aug 05, 2013 at 07:25 PM 0
Share

What do you mean by transfer rotation but only using the amount of rotation?

Say object A has a rotation of 80 degrees, Object B has a rotation of 10 degrees. What do you want to happen?

avatar image superme2012 · Aug 05, 2013 at 07:42 PM 0
Share

ok just so we are on the same page here:

this.transform.Rotate(this.transform.rotation.x, CTRL_PIVOT.rotation.y, this.transform.rotation.z * Time.deltaTime);

is not the answer.

What I'm trying to do in simple terms is apply the amount of rotation from object A to object B. in other words if object A is facing forwards and object B is facing backwards, and then object A is rotated lets say 30 degrees then Object B will also rotate in the correct 30 degrees.

However what I'm really after here is for both objects to be at completely random orientations but still abide by the same rules. When object A is rotated then object B rotates but not having to match the rotations, for example not ObjectA.rotation = ObjectB.rotation.

Sounds simple!

avatar image superme2012 · Aug 05, 2013 at 07:46 PM 0
Share

ok think I may have just found the solution, will post it if works.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Aug 05, 2013 at 08:31 PM

Answer rotations questions like this one can be tricky since words can be visualized different ways. Here is what I think you are asking for:

 #pragma strict
 
 var target : Transform;
 private var offset : Quaternion;
 
 function Start() {
     offset = Quaternion.Inverse(target.rotation) * transform.rotation;
 } 
 
 function Update() {
         transform.rotation =  offset * target.rotation;
 }
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 robertbu · Aug 05, 2013 at 08:37 PM 0
Share

Assu$$anonymous$$g you want to match all three axes, the above code appears to match your video.

avatar image superme2012 · Aug 05, 2013 at 11:33 PM 0
Share

thanks for that will test it out later. I knew it would be something simple.

avatar image
0

Answer by superme2012 · Aug 06, 2013 at 12:13 AM

It's 1:03 AM here and finally got it solved.

I did a hybrid between the code you showed and the TransformConstraint script, I used this to flip the constraints calculations:

this.transform.rotation = Quaternion.Inverse(target.rotation);

works like a charm, and allows to control all or just one axis at a time.

Now for some sleep ;)

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

16 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

Related Questions

Call instantiated object from other script. 1 Answer

How do you make an object following an other object smoothly? 1 Answer

Get the needed rotation to face other object 1 Answer

How to rotate an object once? 2 Answers

Disable script on other object 2 Answers


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