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 instruct9r · May 06, 2017 at 09:17 AM · transformtransform.rotationcopy

Copy localEulerAngles.x from one object to another FAIL

I am trying to get the rotation from one object to another.

They both are childs of different groups, but oriented the same way...

Anyway, i want to copy the rotation only for X axis, but when i rotate the referenced object more than 90 degrees, the object, that should get the X rotation starts rotating back...

This script is applied to the object, that should get the rotation from the referenced Transform

 public class TestRotation_CS : MonoBehaviour 
 {
     public Transform getRotation;
 
     Vector3 getVector;
 
     void Start()
     {
         getVector = transform.localEulerAngles;
     }
 
     void Update()
     {
         getVector.x = getRotation.localEulerAngles.x;    // Get the X rotation of the referenced object
         transform.localEulerAngles = getVector;            // Set the rotation back to this.transform
     }
 }

Weird, that this happens only if i copy the X axis. If i copy the Y or Z it doesn't make any problems and copy them correctly...

Comment
Add comment · Show 1
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 RobAnthem · May 06, 2017 at 04:57 PM 0
Share

Have you tried getting some debug output? It is possible that the X coordinate is negative, but converting to positive on being set. You could always try this.

 getVector = getRotation.localEulerAngles;
 getVector.y = transform.localEulerAngles.y;
 getVector.z = transform.localEulerAngles.z;

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kishotta · May 06, 2017 at 05:41 PM

You might be better off using Quaternions as that's what Unity actually uses to handle rotations. The XYZ angles are just displayed because most of us have trouble visualizing 4-D complex numbers. ;)

 transform.rotation = Quaternion.Euler (target.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z);
Comment
Add comment · Show 5 · 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 instruct9r · May 06, 2017 at 05:54 PM 0
Share

Thanks, but that doesn't work.

I want to take only the X axis and if i try to use that you are suggesting the object, that should take the rotation, is rotating only to 90 \ -90 and goes back. It doesn't spin like the target...

Not to mention, that you are applying localEulerAngle to rotation, which is global. Have you tested, your suggestion??

Also i think it's worth mentioning, that i will also need (sometimes) to take half of the X rotation, so if the target rotates 90 degrees, my transfrom should rotate 45.

avatar image Kishotta instruct9r · May 06, 2017 at 06:17 PM 0
Share

I apologize, I had not tested that solution. I have tested this this though and it seems to be what you're after:

 transform.rotation = Quaternion.Euler (target.rotation.eulerAngles.x, 0, 0); // $$anonymous$$ultiply target.rotation.eulerAngle.x by whatever scale factor you need

It only rotates this transform on its (and the global) x axis to match the targets global x rotation.

avatar image instruct9r Kishotta · May 06, 2017 at 06:43 PM 0
Share

The object, that i am rotating is the target. The other one is gettting the rotation via code like yours. Doesn't this happen in your scene??

It rotates from -90 to 90, like it's clamped in these values...

alt text

Show more comments
avatar image
0

Answer by gaiastellar · Jun 03, 2019 at 11:20 PM

Hi. Did you ever get to the bottom of this. I'm having exactly the same trouble.

Paul

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

113 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

Related Questions

transform.Rotate slows down my moving cube 0 Answers

transform.rotation simple question (noob) 2 Answers

Can't Change Objects Rotation 1 Answer

Issues with copying Y axisrotation of another object 2 Answers

Changes of Transform cancel on next frame after change 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