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 paco morales · Jan 15, 2013 at 04:03 AM · rotationmouseyieldspin

Return to the point of rotation?

Hi,

I'm trying to spin one object with the cursor and when the spinning is finished, the object wait for 2 seconds and then return to the point or rotation.

The rotation is working but, the return to the point of rotation is not working.

Please take a look to my script any advice is welcome

Thanks in advance.

    var rotationSpeed = 20; // rotation speed
    var rotationStart = 0.0; // rotation on start 
       
  
     function Awake () {
         transform.Rotate(rotationStart,0,0);
     }
      
  
     function Update (){
         
         if (Input.GetButton("Fire1")){
         transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
             
         if (Input.GetButtonUp ("Fire1")) {
         yield WaitForSeconds (2.0);
         transform.Rotate(rotationStart,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
1
Best Answer

Answer by Lovrenc · Jan 15, 2013 at 04:08 AM

Try:

 transform.rotation = Quaternion.Euler(rotationStart,0,0);


Your code complete:

 #pragma strict
 
 var rotationSpeed = 20; // rotation speed
 var rotationStart = 0.0; // rotation on start 
 
 function Awake () {
     transform.Rotate(rotationStart,0,0);
 }
 
 function Update (){
 
     if (Input.GetButton("Fire1")){
         transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
     }
     if (Input.GetButtonUp ("Fire1")) {
         StartCoroutine("Return",2);
     }
 }
 
 function Return(){
     yield WaitForSeconds (2.0);
     transform.rotation =  Quaternion.Euler(rotationStart,0,0);
 }
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
avatar image
0

Answer by paco morales · Jan 15, 2013 at 04:19 AM

Hi Lovrenc,

Thanks for your help, I made the change to the script but is not working, here it is my Updated script.

any advice?

Thanks again

    var rotationSpeed = 20; // rotation speed
    var rotationStart = 0.0; // rotation on start 
       
  
    function Awake () {
    transform.Rotate(rotationStart,0,0);
    }
      
  
    function Update (){
         
    if (Input.GetButton("Fire1")){
    transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
             
    }
    }
      
    function Return(){
        
    if (Input.GetButtonUp ("Fire1")) {
    yield WaitForSeconds (2.0);
    transform.rotation = Quaternion.euler(rotationStart,0,0);
    }
    }        
    
  

Comment
Add comment · Show 4 · 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 Lovrenc · Jan 15, 2013 at 04:21 AM 0
Share

Try to use comments for posts like this.

You have function Return now, but you never call it. this goes to update. You dont need Input.GetButtonUp in Return function.

 if (Input.GetButtonUp ("Fire1")) {
   StartCoroutine("Return",2);
 }
avatar image paco morales · Jan 15, 2013 at 04:53 AM 0
Share

Thanks again, but still not working :(

var rotationSpeed = 20; // rotation speed var rotationStart = 0.0; // rotation on start

         function Awake () {
         transform.Rotate(rotationStart,0,0);
         }
 
         function Update (){
 
         if (Input.GetButton("Fire1")){
     transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("$$anonymous$$ouse X") * rotationSpeed);
     }
     if (Input.GetButtonUp ("Fire1")) {
     StartCoroutine("Return",2);
     }
         }
     
         function Return(){
         yield WaitForSeconds (2.0);
         transform.rotation =  Quaternion.euler(rotationStart,0,0);
     }


 
avatar image Lovrenc · Jan 15, 2013 at 05:06 AM 0
Share

euler is capitalised!

avatar image paco morales · Jan 15, 2013 at 05:25 AM 0
Share

Now its working perfectly !! $$anonymous$$any Thanks :)

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Slowing velocity in Rotation? 1 Answer

please help! Game Spinner 0 Answers

Simple rotation script. (loop) 3 Answers

Spin a 2D object with mouse drag 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