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 /
  • Help Room /
avatar image
0
Question by Nordir · Nov 06, 2012 at 07:26 PM · rotationaxis

Rotate an object respectively to other object's rotation on z-axis

Say, we have obj1 and obj2.

I want rotation of obj2 around it's transform.forward to EQUAL the obj1.transform.rotation.z. HOW should i do it?

Note: obj2.transform.rotation.z = obj1.transform.rotation.z;

doesnt work fine if obj2 is already rotated around its x, y and z axis.

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 CuddleMonster · Nov 06, 2012 at 07:57 PM 0
Share

oh.. this isnt what I was thinking. wouldnt this just be solved by: obj2.transform.localRotation.z = obj1.transform.localRotation.z;

avatar image Nordir · Nov 06, 2012 at 08:45 PM 0
Share

Cuddle$$anonymous$$onster, none of the objects is parented so z = z wont work (and i guess it either wouldnt work fine if the child obj had been initially rotated).

avatar image CuddleMonster · Nov 06, 2012 at 10:10 PM 0
Share

That answer was assu$$anonymous$$g that they weren't connected. localRotation should fix it unless there is more details you aren't sharing.

avatar image Owen-Reynolds · Nov 08, 2012 at 10:47 PM 0
Share

Ah, yes, `localRotation` is a Quaternion, and the x,y,z are almost random numbers -- not angles at all.

But, the docs still say that changing a single EulerAngle (just z) will give unpredictable results.

2 Replies

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

Answer by Nordir · Nov 07, 2012 at 09:28 PM

I figured it out. It's damn simple :)

obj2.transform.localEulerAngles.z = obj1.transform.localEulerAngles.z;

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 Tsilliev · Jul 04, 2017 at 10:41 AM 0
Share

Doesnt work, you need to store it, so ins$$anonymous$$d I used the whole rotation to skip storing the value: transform.localEulerAngles = new Vector3(0.0f,$$anonymous$$yCamera.transform.localEulerAngles.y, 0.0f); (CSHARP)

avatar image Owen-Reynolds · Jul 04, 2017 at 02:05 PM 1
Share

This is in javascript. which allows step-through changes. It was the recommended Unity language back in 2012. With C# you'd need to break it out: Quaternion q=obj2.trans.lea; q.z= ... obj1.trans.lea=q;

avatar image Tsilliev Owen-Reynolds · Jul 04, 2017 at 02:48 PM 0
Share

I hate these differences and I hate the people that invent 1000 languages so we chase after our tails. I will also write in what language my method works, will edit my upper comment. Thanks.

avatar image
0

Answer by Owen-Reynolds · Nov 06, 2012 at 10:14 PM

The manual says that reading out a single eulerAngle isn't reliable (even if it did sometimes work.)

So they can both face any direction, but the "roll" should be as equal as possible? Could abuse LookAt to copy #1's UP into #2. Will "flip" when obj2 is facing opposite obj1, but might still look nice:

 Transform tr2 = obj2.transform;
 Vector3 justAhead = tr2.position + tr2.forward;
 obj12.transform.LookAt( justAhead,  obj2.transform.up );

The LookAt won't change the way you face, but will "roll" obj2 to try to align its up with obj1's up. Alternately, if you're already using a lookAt, toss in the alternate up there.

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 Nordir · Nov 07, 2012 at 10:44 AM 0
Share

Thanks Owen, but i need rotations to be precisely equal.

If in Unity editor i click "Local" button and rotate an obj around its Vector3.forward, i see that only its z rotation is changed. I cant get how to change rotation.z without changing x and y in script.

avatar image CuddleMonster · Nov 07, 2012 at 07:50 PM 0
Share

as I said already.... transform.localRotation.z

avatar image Nordir · Nov 07, 2012 at 09:07 PM 0
Share

Cuddle$$anonymous$$onster, localRotation is the same thing as rotation if an obj is not parented:

http://docs.unity3d.com/Documentation/ScriptReference/Transform-localRotation.html

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

12 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

Related Questions

Move an object by rotation 0 Answers

Rotation is starting at 0, how do I use Math.Clamp() on it? 1 Answer

How i can set Start Position and Ending position in ROTATION AROUND AXIS? 0 Answers

Problems with rotating the player on the Y axis C# 0 Answers

Quaternion.LookAt() without restricting manual rotation 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