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 DavidDebnar · Oct 19, 2013 at 05:25 PM · rotationnormalalignsurface normal

Aligning an object with surface normal

Ok, I know how this sounds, but it isn't like that :D. I know there's many questions regarding this, but I believe my problem is a bit different and after working for hours my brain is fried, hence resists to my attempts of programming. I have a character, with this hierarchy

  • Character
    • Visual mesh

It's a top-down shooter, so the character is contrantly spinning around, trying to look at the mouse, which makes the visual mesh spin too. Now, normally, I'd use

 VisualMesh.localRotation = Quaternion.FromToRotation(VisualMesh.up, hit.normal);

But this doesn't work, because as soon as I rotate the character around, it stops being aligned.

So, my question is, how would I go about aligning the visual object with the ground, while making it keep it's parents Y rotation.

Pictures

Character's y rotation set to 0

alt text

Character's y rotation set to 180

alt text

--David

Comment
Add comment · Show 3
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 fafase · Oct 19, 2013 at 05:51 PM 0
Share

Could you provide a picture?

avatar image DavidDebnar · Oct 19, 2013 at 07:01 PM 0
Share

Sure...here you go

avatar image Jamora · Oct 19, 2013 at 09:23 PM 1
Share

Have you tried Visual$$anonymous$$esh.up = hit.normal;?

1 Reply

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

Answer by DavidDebnar · Oct 19, 2013 at 09:50 PM

Thanks Jamora! I didn't know you could assign transform.up and it almost solved my problem. All I had to do then was apply the Y rotation.

 // assigns the raycast's normal direction to the VisualMesh' up directio. this makes it look 'from the surface'
 // then use some lerping, to smooth it all out
 VisualMesh.up = Vector3.Lerp(VisualMesh.up, hit.normal, Time.deltaTime * 10);
 
 // this part makes sure the Y rotation is properly preserved from the parent gameObject as well
 VisualMesh.RotateAround(VisualMesh.position, VisualMesh.up, transform.localEulerAngles.y); 

--David

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

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

Cant align players up vector to surface normal 0 Answers

Raycast Normal in Local Rotation? 1 Answer

rotate parent object to straighten child object? 2 Answers

how to find the normal of a side face from top view? 3 Answers

Rotate a vector3 to a surface normal? 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