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 superventure · Sep 19, 2012 at 08:57 PM · raycastterrainquaternionrotatealign

Quaternions- how to leave out Y rotations...

I don't know how correctly leave out the y factor in this code concept

if(Physics.Raycast(raydown, hit, RayDist , 1<<9)) transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

the code itself correctly aligns the object with the ground's normal, but restricts the object to always to look forward on its y, which blocks my ability to turn or steer with keyboard commands. Is there a way to leave the y rotation out of this equation? Thank you

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
Best Answer

Answer by whydoidoit · Sep 19, 2012 at 11:00 PM

I think what you really want to do is multiply out the FromToRotation - I guess it would look like this:

   transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;

(Or that multiplication might be the other way around)

You want to use transform.up rather than Vector3.up as this object may not be pointing straight up (which is important when applying it like this).

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 superventure · Sep 20, 2012 at 12:23 AM 1
Share

I know this is probably just a simple snip of code to you, but you've just helped me with an important issue I've been struggling with forever. I've really needed a solution, and you've helped me more than I can express here. If I could kiss you, I would. Thank you so much, I appreciate your help.

avatar image Fattie · Sep 20, 2012 at 05:39 AM 0
Share

list LOVE ! dudes I totally want to kiss everyone as well. Awesome!

great question with an epic answer

avatar image whydoidoit · Sep 20, 2012 at 07:35 AM 0
Share

Hey no problem - I clearly remember my eureka moment on Quaternions :)

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

11 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

Related Questions

Align plane to normal but keep Y-axis intact 1 Answer

why am I getting a flipped-out effect from my transform.rotate 2 Answers

Raycast and alighning to the terrain 1 Answer

Rotating with a preferred driection. 0 Answers

Rotate Spawnpoint running into errors 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