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 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 this... 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 this does not take into account front or back. That is, this aligns the 'right' vectors of both, but a ledge has two edges and your alignment will be 180 degrees different dependent on which edge is used. If this 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

with transform.right it aligned them in the X axis, making them paralell, but after this, how can i make the local Z axis of them match? ( i guess its the local Z ), so my character doesn't go trought the platform or stays far away from it, i want it to have the exact local Z position of the ledge...

avatar image robertbu · Oct 31, 2013 at 03:37 PM 0
Share

Just replace 'character.right' and 'ledge.right' with 'character.forward' and 'ledge.forward' in the code above.

avatar image ThiagoTejo · Oct 31, 2013 at 03:56 PM 0
Share
 transform.eulerAngles = ledgeatual.transform.eulerAngles;
 transform.position.y = ledgeatual.transform.position.y;
 transform.right = ledgeatual.transform.right;
 transform.forward = ledgeatual.transform.forward;

I'm using this, but the transform.right and forwards makes no difference... the behaviour is the same even if i remove it.. why?

avatar image robertbu · Oct 31, 2013 at 05:57 PM 0
Share

Your first line sets the rotations equal to each other:

 transform.eulerAngles = ledgeatual.transform.eulerAngles;


So even without the rest of your code, they will be aligned. Note if you want to set rotations eqaual, it is better to do:

 transform.rotation = ledgeatual.transform.rotation;
avatar image aybeone · Jun 03, 2015 at 08:27 PM 0
Share

excellent answer, too bad I cannot upvote you 1000 points :D

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

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

Rolling a capsule lengthways, sideways and twisting with AddTorque 1 Answer

Is there a way to lock my camera's rotation and movement on certain axis? 2 Answers

Rotation eulerangles not adjusting correctly... 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