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 Akrucious · Jan 03, 2013 at 10:20 AM · rotationtransformpositionaxis

How do I make one transform rotation the same as anothers?

Right now I'm trying to take my cameras X rotation and make that my characters right forearm rotation. Can anyone help me with it? I keep getting errors when I try different things.

I can't simply do rightForearmRotation.z = cameraRotation.x; (Mind you, I'm using C#)

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 MaGuSware™ · Jan 03, 2013 at 11:50 AM 0
Share

Try building a new Quaternion.

 Quaternion rot = new Quaternion(rightForearmRotation.x, rightForearmRotation.y, cameraRotation.x, rightForearmRotation.w);

then

 rightForearmRotation = rot;

this will literally make the z of the arm = the x of the camera HOWEVER it may not be result you are hoping it to be, because quaternions are evil.

2 Replies

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

Answer by Piflik · Jan 03, 2013 at 10:40 AM

If a component of a vector is read only (like transform.position), you can use a temporary vector, modify it and then replace the original vector with it.

 Vector3 temp = transform.position;
 temp.z = target.transform.position.x;
 transform.position = temp;

But in this case, you can simply do this (methinks):

 transform.rotation = Quaternion.Euler(transform.rotation.x, transfom.rotation.y, target.transform.rotation.x);


Since Quaternion.Euler already returns a new Quaternion.

Modifying the components of a Quaternion directly is a bad idea in any case, unless you know exactly how Quaternions work.

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 Akrucious · Jan 03, 2013 at 11:01 AM 0
Share

Neither work, when I try to make it a vector3 it tells me "Assets/Scripts/Player/Arm$$anonymous$$ovement.cs(14,31): error CS0236: A field initializer cannot reference the nonstatic field, method, or property"

As far as the quaternion option, I can't make heads or tails of it.

avatar image Simon-O · Dec 20, 2016 at 08:58 PM 0
Share

That should be...

transform.rotation = Quaternion.Euler(transform.rotation.x, transfom.rotation.y, target.transform.rotation.z); (Note the final z)

avatar image
0

Answer by Maulik2208 · Jan 03, 2013 at 11:51 AM

     public GameObject cube1;
     public GameObject cube2;
     
 
     // Use this for initialization
     void Start () 
     {
         cube1.transform.rotation = cube2.transform.rotation;
     
     }
   

For checking this script create a new scene and take 2 cubes......then rotate the 2nd cube as you wish......Drag this script to cube 1........assign both cubes to inspector panel.....Hit play and Done.....Cube is Rotated to Rotation of Cube 2......Enjoy.....If found useful then don't forget to mark the answer......

Comment
Add comment · Show 4 · 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 MaGuSware™ · Jan 03, 2013 at 11:54 AM 0
Share

I like how you didn't read his question. He wants the z of his a arm to = the x of the camera. Not a whole rotation clone..

avatar image Maulik2208 · Jan 03, 2013 at 12:03 PM 0
Share

That was for a sample to Copy the whole Rotation.....For $$anonymous$$ore Specification he can do modification in my code....like say cube1.transform.rotation.z = cube2.transform.rotation.x; And it will work.....Then all he has to Do is Replace the Cube1 & Cube2 to his Gameobject......

But Thanks For you $$anonymous$$gestion i will keep it in $$anonymous$$d.... @$$anonymous$$aGuSware™

avatar image kocha_belgisi Maulik2208 · Mar 01, 2020 at 07:19 PM 0
Share

I have the same probles Piflik, your first worked for me, but as magusware sad, it isn't was he asket for, your second answer, "cube1.transform.rotation.z = cube2.transform.rotation.x" doesn't work, it sas it you can't modify transform.rotation. Do you have a solution for this?

avatar image PlatPlayz · Feb 11, 2018 at 05:55 PM 0
Share

For some reason it rotates a frame later than the second object for me.

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

14 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

Related Questions

transform.position on basis of rotation 0 Answers

Problem changing rotation of 3rd Person Controller 1 Answer

Align objects based on child objects 0 Answers

Ragdoll breaks and flys far into the air... 0 Answers

Follow x rotation of a target object. 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