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 NicoLocke · Jul 02, 2013 at 12:31 PM · quaternion

Quaternion.identity?

I want to reset the rotation of an object once it reaches a specific coordinate on the z axis...

I have this which works fine at the moment...

 var target : GameObject;
 
 function Start () {
 
 }
 
 function Update () {
 
 
     if(transform.position.z == -1.0f)
     
     target.transform.rotation = Quaternion.identity;
 
 }

However instead of the reset being an instant change, is there a way of adjusting the script so that the object actually rotates back to the points of 0,0,0 instead of instantly reverting to 0,0,0?

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

Answer by Oana · Jul 02, 2013 at 12:45 PM

Try something like this:

  var rotateBack = false;
     var speed = 10;
     
     function Update(){
        if (transform.position.z == -1.0f) rotateBack = true;
     
        if (rotateBack){
           if (target.transform.rotation == Quaternion.identity){
              rotateBack = false;
           }else{
              target.transform.rotation = Quaternion.Lerp(target.transform.rotation, Quaternion.identity, speed*Time.deltaTime);
           }
        }
     
     }

(not tested in editor, but should give you an idea of how to do it)

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 NicoLocke · Jul 02, 2013 at 01:10 PM 0
Share

Thank you, this is how I solved my problem...

 var target : GameObject;
 var speed = 10;
  
     function Update(){
        if (transform.position.z == -1.0f) 
  
              target.transform.rotation = Quaternion.Lerp(target.transform.rotation, Quaternion.identity, speed*Time.deltaTime);
           
         }
avatar image Pangamini · May 14, 2019 at 11:48 AM 0
Share

While this will somehow give you a result that kind of looks like something you want, this is not how you use lerp. The duration of the smooth motion will be dependent on the framerate and completely unpredictable. It's been discussed so many times now

avatar image
3

Answer by lighting · Jul 02, 2013 at 12:42 PM

Please use Quaternion.Lerp as described here: in the documentation, where target Rotation will be Quaternion.identity. I hope this is what you're looking for. :)

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 NicoLocke · Jul 02, 2013 at 01:11 PM 1
Share

Cheers for putting me on to lerp! Will come in very handy.

avatar image Naikooooo · Feb 04, 2016 at 04:23 PM 0
Share

The link died, do you happen to know the new location?

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

19 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

Related Questions

How to fix Child Object Rotations.? 1 Answer

AirPlane-Like Rotation ( like in GTA games) 1 Answer

Quaternion, Eulers and Problems 1 Answer

Quaternion.LookRotation Active when not active. 0 Answers

Projectile Rotation To Match Direction Shot? Mobile Joystick 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