Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 knuckles209cp · Apr 11, 2019 at 12:50 AM · rotationjavascriptterraindatasmoothing

Smoothly rotate to ground?

I am creating a snowboarding game, My character is going to have to match the slope so it doesn't go off into the air randomly. I have created the script to achieve this, but as the slope changes, it snaps to the rotation instead of smoothly transitioning. I have tried finding anything about it, Unfortunately they all use C# and I am after unity java. I have tried Lerping and RotateTowards but I havn't had any luck.

 var hit : RaycastHit;
      if (Physics.Raycast(transform.position, Vector3.down, hit)) {
          transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
      }
 
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
0

Answer by toddisarockstar · Apr 11, 2019 at 07:32 AM

sorry i don't have time to test. transform up and the hit.normal are in a euler rotation format. euler angles represent rotations in 3 numbers instead of 4 like a quaterton. so you would assign your result to transform.eularangles or cast it. your comparison is between the two "up" rotations. and the math will result in a an up rotation. if your character ends up looking at the sky after running this just add 90 to the x axis right before you assign your result back to the character. on a side note, over the last couple years seems no one talks about or seems to be using unity's javascript anymore. C# seems to be the popular language for unity and everything else. it's not really javascript. it's more commonly called Unityscript. because the type of coding only works with unity. i would recommend learning c# just cause it is compatible with everything else and everyone knows it. also, as you get into more advanced programming you have access to mr bill gate's fun librarys.

 var dir : Vector3 =  Vector3.RotateTowards(transform.up,hit.normal, speed*time.deltatime, 0);
 
 // you may have to add 90 to the x in dir here if your character 
 // is flipping over 
 
 transform.eulerAngles = dir;
Comment
Add comment · Show 1 · 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 knuckles209cp · Apr 11, 2019 at 10:10 AM 0
Share

Hi there, Thank you for the reply. I have added to the script since I posted and tried to apply your script to $$anonymous$$e with no luck, $$anonymous$$aybe I am putting it in the wrong spot. Please assist me , here is the current code ( working )

 if(Grounded == true){
 var hit : RaycastHit;
      if (Physics.Raycast(transform.position, Vector3.down, hit)) {
          var distanceToGround = hit.distance;
          transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
          Snow$$anonymous$$esh.transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
          distToGround = distanceToGround;   
          
          if(  Snow$$anonymous$$esh.transform.rotation != Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation){
              print("crash");
          }
 }  
 }

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

183 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

Smooth Rotation Help 1 Answer

Determining Look Rotation As > A Number? 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

How to change the pivot point of a mesh in script? 1 Answer

Scripting question about rotating on collision 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