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 The 3D Ninja · Nov 30, 2010 at 02:10 AM · rotationeasing

Add Easing to Transform.Rotate

Hi,

I'm using a C# script to rotate an object based off a two finger rotate gesture. The following script works great, but I'd like to add a little easing to the rotation. I've tried implementing some easing equations, but can't get things to work.

I thought about trying to use Quaternion.Slerp, but I need angleThen and angleNow to be of type Quaternion and I'm not sure how to convert these values using Quaternion constructor.

transform.rotation = Quaternion.Slerp (angleThen, angleNow, Time.time * 0.4);

I'd greatly appreciate any help or advice!

Thanks,

Wes

float zDistanceFromCamera = Vector3.Distance(Camera.main.transform.position,transform.position); Vector3 screenPosition0 = new Vector3(touch0.position.x,touch0.position.y,zDistanceFromCamera); Vector3 lastScreenPosition0 = new Vector3(touch0.position.x - touch0.deltaPosition.x,touch0.position.y - touch0.deltaPosition.y,zDistanceFromCamera);

             Vector3 screenPosition1 = new Vector3(touch1.position.x,touch1.position.y,zDistanceFromCamera);
             Vector3 lastScreenPosition1 = new Vector3(touch1.position.x - touch1.deltaPosition.x,touch1.position.y - touch1.deltaPosition.y,zDistanceFromCamera);


             float angleNow = Mathf.Atan2(screenPosition0.x - screenPosition1.x, screenPosition0.y - screenPosition1.y) * Mathf.Rad2Deg;
             float angleThen = Mathf.Atan2(lastScreenPosition0.x - lastScreenPosition1.x, lastScreenPosition0.y - lastScreenPosition1.y) * Mathf.Rad2Deg;

             float angleDelta = (angleNow - angleThen);
             transform.Rotate(Vector3.up, angleDelta, Space.Self);

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 Mendicant · Nov 30, 2010 at 08:44 AM

You could try something like:

    var str : float = RotationSpeed * Time.deltaTime;
    transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.AngleAxis(0, Vector3.up), str);

http://unity3d.com/support/documentation/ScriptReference/Quaternion.AngleAxis.html

Comment
Add comment · Show 2 · 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 The 3D Ninja · Dec 01, 2010 at 01:25 AM 0
Share

Thanks very much for the help! Unfortunately, I couldn't get this solution to work. It seems that the rotation keeps wanting to jump back to it's original value. I'll keep messing with it. Quaternion.AngleAxis is a good use and will come in handy.

avatar image demize2010 · Apr 21, 2011 at 08:55 PM 0
Share

$$anonymous$$endicant is right, quanteraion lerp is what you need. Check the script ref but in the arguments you need (original angle, target angle, time) if I'm not mistaken.

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

No one has followed this question yet.

Related Questions

Rotation Ease-In-Out with MAX Rotation Speed 1 Answer

What is the best way to ease a rotation? (js) 1 Answer

easing camera rotation after mouse up? 0 Answers

Flip over an object (smooth transition) 3 Answers

Rotation speed increase gradually 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