• 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
Question by Agurus1 · Dec 02, 2012 at 10:29 PM · 2drotationspriteslerp

Smoother Sprite 2D turret rotation (slerp?)

So I am making a turret, that targets enemy units as they are walking past the turret. Everything is in 2D (isometric view).

I have basically made it so the turret basically "follows"/rotates when a enemy unit walks past it, however once the turret needs to go back to next target next minion, it instantly jumps to that frame.

For example, I have sprites at 5 degree intervals, all the way around. So a minion walks by, and the turret rotates to 90 degrees. Then another enemy comes and is at 270 degrees, the tower will instantly FLIP to 270..I want it to run/have a smooth animation from 90-270 degrees.

So I am trying to use SLERP (with locked x and z axis), however slerp only rotates my static image...and that in random x/y/z directions even though I have them locked.

My question is what can I do to achieve the smoother animation above from a case such as 90 degrees to 270 degrees and not jump?

Comment
numbus

People who like this

1 Show 0
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

  • Sort: 
avatar image

Answer by zee_ola05 · Feb 03, 2014 at 02:28 PM

let's say that your current rotation is in 90, and targetAngle is 90. You can add a variable turnSpeed and then use this code in your Update...

 float targetAngle = 90;
 float turnSpeed = 5;
 transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.Euler (0, 0, targetAngle), turnSpeed * Time.deltaTime);
Comment
alok-kr-029
Bob-The-Zealot
DotusX
numbus
tonyvranic
lucasbas2015
dman8723
MikaFika
hongjefferson211

People who like this

9 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

LookAt() not working with mouse as target in 2D 1 Answer

Rigidbody2d Collision Breaks Quaternion.Slerp 2 Answers

Rotate Sprite along shape? 0 Answers

2D sprite rotation with velocity and interpolation 1 Answer

Change Sprite Origin in 2D 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