• 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 ThiagoTejo · Oct 31, 2013 at 02:44 PM · rotationaxisalignclimb

Align X axis of one object according to another

Hello guys, i'm currently working on a Climbing ledge system, and i'm almost done, but i'm having a problem to place the character on the right place when he grabs the ledge. Currently, i'm using transform.rotation.eulerAngles to make my character face the ledge, and then i transform the positions z and y of my characters to match the ledge, and it works fine, just like Pic 1! but, if i rotate the platform, the character will match the global Z position from the center of the ledge ( just like Pics 2 and 3 ), and that's obviously causes some errors. then, i decided to try another method:

After i rotate my character to face the ledge, i could make the X axis of my character match the X axis of the ledge ( see pic 4 ). but i don't know how to make t$$anonymous$$s... if its possible, can someone help me? and if you guys can come up with a simpler solution, its fine too :)

alt text

axis.png (74.3 kB)
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
1

Answer by robertbu · Oct 31, 2013 at 02:58 PM

Assuming they are parallel you can do:

 character.right = ledge.right;

If you want to do it over time:

 var q = Quaternion.FromToRotation(character.right, ledge.right);
 transform.rotation = Slerp(transform.rotation, q * transform.rotation, speed * Time.deltaTime);

Note t$$anonymous$$s does not take into account front or back. That is, t$$anonymous$$s aligns the 'right' vectors of both, but a ledge has two edges and your alignment will be 180 degrees different dependent on w$$anonymous$$ch edge is used. If t$$anonymous$$s is an issue, you can check the angle:

 var align : Vector3;
 if (Vector3.Angle(character.right, ledge.right < 90)
     align = ledge.right;
 else 
     align = -ledge.right;
 
 var q = Quaternion.FromToRotation(character.right, align);
 transform.rotation = Slerp(transform.rotation, q * transform.rotation, speed * Time.deltaTime);
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 ThiagoTejo · Oct 31, 2013 at 03:30 PM 0
Share
avatar image robertbu · Oct 31, 2013 at 03:37 PM 0
Share
avatar image ThiagoTejo · Oct 31, 2013 at 03:56 PM 0
Share
avatar image robertbu · Oct 31, 2013 at 05:57 PM 0
Share
avatar image aybeone · Jun 03, 2015 at 08:27 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Aligning to a specific axis (6 DOF Descent-like movement) 1 Answer

Align an axis to a plane 0 Answers

Orbit Collision Axis 0 Answers

Cant align players up vector to surface normal 0 Answers

rotation to axis conversion problem? 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