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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by MuseumTourGames · Aug 12, 2013 at 08:25 PM · c#2drotationspeed

Smoothed Rotation with 2D Top-Down View

I was wondering how I could convert code that makes the character simply face the direction that the axis is facing:

 if(direction.sqrMagnitude > 0.1f) { transform.LookAt(transform.position + direction); }

To code that rotates the character at a pre-determined velocity toward that rotation, so as to make the character rotation "smoothed".

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
Best Answer

Answer by robertbu · Aug 13, 2013 at 02:52 AM

At the top of the file:

 var qTo : Quaternion;
 var speed = 85.0;  // Degrees per second

Wherever you are setting the direction:

 if (direction.sqrMagnitude > 0.1f) {
     qTo = Quaternion.LookRotation(direction);

}

Then in Update():

 transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, speed * Time.deltaTime);
Comment
Add comment · Show 5 · 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 MuseumTourGames · Aug 13, 2013 at 04:33 PM 0
Share

This worked perfectly. Thank you so much!!

$$anonymous$$ind if I ask another question? Good.

I want to accomplish the same thing, but with mouse input now. I want the player to be able to rotate towards looking at the mouse position as well..I have the mouse input and joystick input code separated, I understand how that works.

But how would I implement this system given a mouse position?

THAN$$anonymous$$ YOU SO $$anonymous$$UCH <3

avatar image robertbu · Aug 13, 2013 at 04:43 PM 0
Share

I just answered this question about facing the mouse position:

http://answers.unity3d.com/questions/513787/rotate-an-object-to-face-mouse.html

This question uses Transform.LookAt(). The difference between LookAt() and LookRotation() is that LookAt() uses a position in 3D space where LookRotation() uses a direction vector. So to get your direction as used in the above code to use in LookRotation():

 direction = position - transform.position;

...where 'position' is the variable in the script at the link.

avatar image MuseumTourGames · Aug 13, 2013 at 04:48 PM 0
Share

Thanks man. I really appreciate it. I've learned so much about Unity through the Answers site.

Show more comments

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

16 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

Related Questions

Start Coroutine after other has finished 4 Answers

Flip over an object (smooth transition) 3 Answers

Camera to follow the player in the form of radius 1 Answer

Vector2 Lerp. Probably a simple solution C# 4 Answers

Flipping parent object in 2d with negative x scale causes rotation issues for children gameobjects 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