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
0
Question by aman_jha · Oct 13, 2014 at 03:15 PM · c#rotationjavascriptquaternionlerp

Smoothly Rotate 2D sprite 90 degrees on click

Hey Unitarians,

I have a simple 2D square in my scene, and I want it so that whenever the user clicks the screen, the square rotates itself 90 degrees to the left. I want it to smoothly rotate over a span of half a second.

So far, I can make the square rotate 90 degrees to the left instantaneously by using transform.Rotate (Vector3.forward * -90f);, but the problem is that it does that instantly, and not smoothly over a period of half a second

I tried using Quaternion.Lerp, but it doesn't work. It turns one degree and then stops and won't turn again when I click it. Also, before I clicked for the first time, there were error messeges that complained of the transform.rotation assign attempt being not valid. I have never used Quaternions nor Lerps before, so I don't know how it works at all.

I don't want to use the above methods. I have no idea how to make it work. If anyone could help me, it would be a godsend.

Thanks in advance, Aman Jha

Comment
Add comment · Show 5
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 KpjComp · Oct 13, 2014 at 03:30 PM 0
Share

I knocked up a wiggle script the other day, that wiggled objects smoothly,. This used the Lerp function, if you use this as a base you should be able to get what your after, ins$$anonymous$$d of transfrom you could apply to rotation, and ins$$anonymous$$d of random you would use set values ins$$anonymous$$d. http://answers.unity3d.com/questions/806893/how-can-i-script-a-wiggle.html

avatar image robertbu · Oct 13, 2014 at 04:37 PM 0
Share

Smooth rotation over time has been posted to Unity Answers many times. If you are just looking for a solution, take a look at the $$anonymous$$oveObject script in the Unity Wiki (it does rotation), and iTween (free from the Asset store).

avatar image aman_jha · Oct 13, 2014 at 04:51 PM 0
Share

@robertbu Does iTween support 2D objects? Also is it a significant file size? (I'm developing for mobile).

avatar image Diablo404 · Oct 13, 2014 at 04:54 PM 0
Share

$$anonymous$$aybe also check LeanTween. It's faster and I find it easier to use. And it's free too.

avatar image robertbu · Oct 13, 2014 at 06:58 PM 0
Share

In general, you can thing of Unity's 2D and 3D with an orthographic camera, so yes iTween (or LeanTween) will work fine. And you should not see any performance issues from using them. But your problem is only the one you ask about, search Unity Answers for the many answers dealing smooth rotation.

2 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by liyokikon · Oct 13, 2014 at 06:27 PM

Why don't you try using something like iTween?

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 aman_jha · Oct 14, 2014 at 12:09 AM 0
Share

Already got that answer from robertbu in the comments, but I can't accept that so I'll accept yours lol.

avatar image
0

Answer by alexander11 · Oct 13, 2014 at 08:35 PM

try using Time.deltaTime

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

32 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

Related Questions

better way to rotate instead Coroutine 1 Answer

Flip over an object (smooth transition) 3 Answers

Rotation jumping to a different rotation after rotating a certain amount 0 Answers

Quaternion.Lerp shaky while in coroutine? 1 Answer

Pinball Flipper using Quaternion.Lerp? 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