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 /
avatar image
0
Question by Bablo · Feb 27, 2011 at 08:56 PM · rotationquaternionlerpsmooth

Smoothing the characters rotation with Lerp

Hey! I have a character, which will turn to face a certain direction when not moving. Currently the rotation after the character stops moving happens very fast, which looks ugly. So I'm trying to smooth it out with Lerp.

I've tried to code it but its currently not working, it doesn't give any errors but some of you might see whats wrong here.

public Quaternion dir; public float smoothSpeed = 0.5f;

void Update () { if(Input.GetAxis("Vertical")==0 && Input.GetAxis("Horizontal")==0) { dir.y=-135;

     transform.rotation = Quaternion.Lerp(transform.rotation, dir, Time.deltaTime * smoothSpeed);
 }

}

}

The direction is right, but it is still doing the rotation instantly.

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

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

Answer by AngryOldMan · Feb 27, 2011 at 10:53 PM

change

transform.rotation = Quaternion.lerp

to

transform.rotation = Quaternion.Slerp
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 Bablo · Feb 28, 2011 at 06:02 AM 0
Share

Doesn't seem to help. I tried with different time values too but nothing seems to help. Anyone else notice anything wrong here?

avatar image Bablo · Feb 28, 2011 at 07:53 AM 0
Share

Ok got it working, seems that I had a problem with the time value on Slerp, works with both, Lerp and Slerp. I didn't realize that the time value was between 0 and 1. Thanks for the help anway. :)

avatar image
0

Answer by servival · Jun 23, 2015 at 06:20 AM

Here is the Final Code:

 using UnityEngine;
 using System.Collections;
 
 public class Smoothrotatoin : MonoBehaviour {
 
     public Quaternion dir; 
     public float smoothSpeed = 0.5f;
     
     void Update () { if(Input.GetAxis("Vertical")==0 && Input.GetAxis("Horizontal")==0) { dir.y=-135;
             
             transform.rotation = Quaternion.Lerp(transform.rotation, dir, Time.deltaTime * smoothSpeed/100);
         }
         
     }
     
 }
 
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

1 Person is following this question.

avatar image

Related Questions

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

How would I smooth out a Quaternion? 2 Answers

Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers

Clamped Turret Doesn't Want to Lerp the Other Way 2 Answers

Unity Quaternion Problem (Should be A Bug?) 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