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
1
Question by MisteriosM · Jun 11, 2014 at 11:07 PM · javascriptrotate objectfunction updateparent transform

Copy rotation values in between objects.

I need to coppy the rotation values of an object to other objects ingame.

I wrote :

 var target : Transform;
 
 function Update () {
     transform.rotation.x = target.transform.rotation.x;
     transform.rotation.y = target.transform.rotation.y;
     transform.rotation.z = target.transform.rotation.z;
 }

But it doesn't work. The Rotations do update but they are not 1:1 the same and vary within a 40° range on all axis. This is way to much. How else could I do it? Parents don't Work since there are several objects depending on a single one, all with a big offset and transforming the parents rotation only causes the Objects to shift regarding their offset.

Comment
Add comment · Show 2
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 christoph_r · Jun 11, 2014 at 11:09 PM 1
Share

First of all, if you want to set the rotation of the target object, it needs to be on the left side of the equation. The second thing is: Does target.transform.rotation = transform.rotation; do the trick?

avatar image MisteriosM · Jun 12, 2014 at 07:54 AM 0
Share

No,, target is the Object the rotation is co$$anonymous$$g from. Yea I should have named it otherwise but this is only a part of the code.

1 Reply

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

Answer by Ricewind1 · Jun 12, 2014 at 01:55 AM

 Vector3 newRotation = new Vector3(go2.transform.eulerAngles.x, go2.transform.eulerAngles.x, go2.transform.eulerAngles.z);
 gameObject.transform.eulerAngles = newRotation;

Or the following (untested)

 Vector3 newRotation = gameObject.transform.rotation.eulerAngles;
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 MisteriosM · Jun 12, 2014 at 08:25 AM 0
Share

Took me ages to figure out what didn't work. Was in JS ins$$anonymous$$d of C# :P Fail. Also you had x twice. But thats fine :D In the end, this is what I was looking for. Thank you :D

     void Update () {
         var target = GameObject.Find("center");
         Vector3 newRotation = new Vector3(target.transform.eulerAngles.x, target.transform.eulerAngles.y, target.transform.eulerAngles.z);
         this.transform.eulerAngles = newRotation;
     }

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

23 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

Related Questions

Save Timer HighScore 1 Answer

An instance of type (Script) is required to access non static member (Script) 1 Answer

JS file deleting multiple game objects 0 Answers

Breaking a loop, Javascript? 3 Answers

GuiTexture Width 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