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 Slingo_the_cat · Mar 12, 2015 at 07:47 PM · scriptingbasics

How to make one object's rotation match another?

I am quite new to unity.

I have two objects, "Object A" and "Object B". How can I write a script to make Object A automatically rotate to Object B's rotation?

For Example: If object B's rotation is X:5, Y:2, Z:3.2, object A will rotate to X:5, Y:2, Z:3.2.

Thanks in advance

Comment
Add comment
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

1 Reply

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

Answer by tanoshimi · Mar 12, 2015 at 07:49 PM

 B.transform.rotation = A.transform.rotation;

?

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 Slingo_the_cat · Mar 12, 2015 at 08:01 PM 0
Share

Javascript or C#? Can I have a full script rather than one line?

avatar image Cherno · Mar 12, 2015 at 08:20 PM 0
Share

That line of code is all you need. If you want a full script, create a new one and insert this line :P

Also, it will work for both C# and UnityScript (which is NOT JavaScript!).

B and A are just gameObject variables holding the relevant gameObjects.

avatar image incorrect · Mar 12, 2015 at 08:30 PM 0
Share

That line of code is all you need. If you want a full script, create a new one and insert this line :P

You know what? He will miss references to those gameobjects. ;)

avatar image Owen-Reynolds · Mar 13, 2015 at 12:47 AM 0
Share

And the title says "match rotation" but in the text "automatically rotate to" sounds more like its wanted as gradual, which is a whole different thing (but easy to look up.)

And the example has all numbers from 1-5. Odd choices for degrees for rotation. $$anonymous$$akes me wonder if the Q is really about looking at a point?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make my FlashLight start off instead on. 1 Answer

JS and C# how to open in different programs. 1 Answer

Overwrite the value in my List but why? 0 Answers

Multiple Scripts attached to a GameObject vs Inheritance 0 Answers

error CS0029: Cannot implicitly convert type `UnityEngine.ParticleSystem.MinMaxCurve' to `float' 0 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