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 tmalhassan · Sep 18, 2017 at 03:28 AM · c#unity 5rotationlerpsmooth

Why is my object not rotating smoothly ? C#

Hello. I am trying to rotate my object smoothly using Quaternion.Lerp(). But for some reason it's not rotating smoothly. Instead, it is just snapping to that position. How can i fix this?

This is the code:

 float rotateFloat = (((randomReward + 1) * 60) - 30) - transform.rotation.z;
 Quaternion targetRotation = Quaternion.Euler(new Vector3(0, 0, rotateFloat));
 transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, f_difX * Time.deltaTime);

I tried to use Quaternion.RotateTowards() instead, it did rotate smoothly. But i faced another problem which is the direction of the rotation. I did some research and found that Quaternion.RotateTowards() Finds the shortest way to rotate to the targetRotation point, which defies the whole point of spinning the object in a both directions.

P.S. i tried to use Quaternion.Slerp() and i got the same result as the Quaternion.Lerp()

Any help is very much appreciated.

Edit:

I'm trying to create a spin wheel. the idea of that spin wheel is to follow the direction of the player's swipe. f_difX is basically the point of where the player lefts his finger off the screen - the point where he touched the screen before swiping. And then i decrease f_difX with -1 every frame until it reaches zero (This creates the spinning animation). The code above is a function that is called when f_difX < 100 (which is the last round) to lerp towards the chosen randomReward. The random reward is a gameObject that is selected randomly from a GameObject list. The first line of the code above is to calculate the amount of float the wheel should rotate to reach the center position (0 on X axis). For now, the code works properly and it actually rotates correctly to face the right angle. But my proplem is that it snaps to the angle and not rotate smoothly.

Also as i said above, i tried it using Quaternion.RotateTowards() which worked nicely and the wheel rotated smoothly. But i faced the problem of it following the closest arc to reach the targetRotation, which defies the whole idea of the wheel spinning according to the player's swipe. I tried to look online to find a way to reverse the Quaternion.RotateTowards() to follow the other direction, but i had no luck.

Comment
Add comment · Show 2
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 khemistry · Sep 18, 2017 at 07:03 AM 0
Share

What is the value of f_difX?

A lerp snapping to its final value sounds like the t value is greater than 1.

Also, what is randomReward?

It looks like you're changing the goal of the Lerp every frame, so that could be causing issues.

avatar image tmalhassan khemistry · Sep 18, 2017 at 08:32 AM 0
Share

I'm trying to create a spin wheel. the idea of that spin wheel is to follow the direction of the player's swipe. f_difX is basically the point of where the player lefts his finger off the screen - the point where he touched the screen before swiping. And then i decrease f_difX with -1 every frame until it reaches zero (This creates the spinning animation). The code above is a function that is called when f_difX < 100 (which is the last round) to lerp towards the chosen randomReward. The random reward is a gameObject that is selected randomly from a GameObject list. The first line of the code above is to calculate the amount of float the wheel should rotate to reach the center position (0 on X axis). For now, the code works properly and it actually rotates correctly to face the right angle. But my proplem is that it snaps to the angle and not rotate smoothly.

Also as i said above, i tried it using Quaternion.RotateTowards() which worked nicely and the wheel rotated smoothly. But i faced the problem of it following the closest arc to reach the targetRotation, which defies the whole idea of the wheel spinning according to the player's swipe. I tried to look online to find a way to reverse the Quaternion.RotateTowards() to follow the other direction, but i had no luck.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Animatick · Sep 18, 2017 at 09:00 AM

I'm not sure how you had set up your Quaternion.Slerp, but for me, I was working on a project that used an external device to rotate the camera in the engine. the way that I got it to not jar around or snap is this

    Quaternion toRotation = Quaternion.Euler(x, y, z);
             transform.rotation = Quaternion.Slerp(transform.rotation, toRotation, 0.3f);

Like I said I'm not sure if this is the way you tried, but this is what worked for me

I hope this helps.

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 tmalhassan · Sep 18, 2017 at 09:50 AM 0
Share

Yeah that's exactly how i tried it. But no luck! Thanks for the reply :)

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

424 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 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 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

Move position with smoothing 0 Answers

Flip over an object (smooth transition) 3 Answers

Is it possible to use a quaternion from a gameobjects position to another gameobjects position? 1 Answer

How to ROTATE an object without slowing the ends (lerp) 3 Answers

How would I smooth out a Quaternion? 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