Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Jan 23, 2015 at 05:01 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by LaneFox · Jan 23, 2015 at 07:05 AM · rotationvector3quaternionlerpsmooth

How would I smooth out a Quaternion?

         void DoOrientation()
         {
             if (go = null)
             {
                 Finish ();
                 return;
             }
 
             v1 = leftFront.Value;
             v2 = leftRear.Value;
             v3 = rightFront.Value;
             v4 = rightRear.Value;
 
             Vector3 upDir;
             upDir = (Vector3.Cross (v1, v3) +
                      Vector3.Cross (v3, v4) +
                      Vector3.Cross (v4, v2) +
                      Vector3.Cross (v2, v1)).normalized;
 
             go.transform.rotation = Quaternion.FromToRotation(go.transform.up, upDir) * go.transform.rotation;
         }


I feel like I'm almost there but I can't figure out how to use Quaternion.Lerp in this case while I've got Quaternion.FromToRotation actually figuring things out.

The use case is I have 4 feet of a Quadruped defined and I'm using the normal average to orient the body of the Agent / Vehicle / Quadruped... I would like this to be smoother because it's quite jerky as is but I'm fairly burnt out trying to sort out the Vectors and/or Quaternions for this as it really isn't my forte so many someone can shine some fresh light on my problem :s ..

Thanks

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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by hardmode2236 · Jan 23, 2015 at 07:48 AM

i just recently had to figure out Quaternion.lerp as well, and i hope i'm understanding your code right:

you want the rotation of the "vehicle's" body to match the average direction of its 4 feet?

what you could try is something like this

 go.transform.rotation = Quaternion.Lerp(go.transform.rotation, targetRotation.rotation, rotationSpeed);

you would need to set the upDir's averaged Vector3 into a transform i think, because the Quaternion.Lerp function only deals with Quaternions - not Vector3s. and use that as the "targetRotation.rotation"

and as for the rotation speed: 1 is instant rotation i think. so to make it smooth try .1 or so.

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

Answer by LaneFox · Jan 23, 2015 at 05:01 PM

         void DoOrientation()
         {
             if (go == null)
             {
                 Finish ();
                 Debug.LogWarning("GameObject Missing.");
                 return;
             }
 
             v1 = leftFront.Value;
             v2 = leftRear.Value;
             v3 = rightFront.Value;
             v4 = rightRear.Value;
 
             Vector3 upDir;
             upDir = (Vector3.Cross (v1, v3) +
                      Vector3.Cross (v3, v4) +
                      Vector3.Cross (v4, v2) +
                      Vector3.Cross (v2, v1)).normalized;
 
             // create and define the target rotation using the average direction of the feet
             Quaternion targetRotation = Quaternion.FromToRotation(go.transform.up, upDir) * go.transform.rotation;
 
             // apply the lerp from the current rotation toward the target rotation with a speed.
             go.transform.rotation = Quaternion.Lerp(go.transform.rotation, targetRotation, speed.Value);
 
             // working // old code, simpler. //
             // go.transform.rotation = Quaternion.FromToRotation(go.transform.up, upDir) * go.transform.rotation;
             // working //
         }

Solved code above.

Had to create a transform as a target which solved the averaging of the direction first, then Lerp between the go rotation and the solved Quaternion.

Thanks for hardmode2236 for pointing this out.

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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to smoothly rotate to certain directions using input axis 1 Answer

Issues with Lerps 2 Answers

Smoothing the characters rotation with Lerp 2 Answers

How to know if a gameobject is rotating? 1 Answer

How to ROTATE an object without slowing the ends (lerp) 3 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