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 07:15 PM · rotationyieldslerp

Slowing velocity in Rotation?

Hello everyone,

I'm working in a script that makes a 3d Object spin with the mouse. The rotations works very well, then when the 3d object stops and wait for 2 seconds and then return to the origin point of rotation.

But I need to control the velocity of returning, because now is so fast. I tried with Quaternion.Slerp, but I don't know very well how to put it.

Thanks for your time,

Please see to my Script.

 var rotationSpeed = 20; // rotation speed
 var rotationStart = 0.0; // rotation on start 
 var speed = 0.1; // return speed
  
 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.Slerp (rotationStart,0,0) Time.time * speed);
 
 }

Thanks in advance

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

Answer by robertbu · Jan 15, 2013 at 07:45 PM

Quaternion.Slerp() needs to be called from or inside Update() so it is called repeatedly. And your method call here is incorrect...should be something like Quaternion.Slerp(transform.rotation, Quaternion.identy, Time.time * speed); Also take a look at Quaternion.RotateTowards() if you want constant speed.

Comment
Add comment · Show 3 · 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 paco morales · Jan 15, 2013 at 08:17 PM 0
Share

Hi Robert, I made this change but still is not working, can you please tell me what is wrong with my script?

var rotationSpeed = 20;
var rotationStart = 0.0;
var speed = 0.1;

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")){

Return(); }

}

function Return(){

yield WaitForSeconds (2.0); Quaternion.Slerp(transform.rotation, Quaternion.identy, Time.time * speed);

}

avatar image robertbu · Jan 15, 2013 at 09:19 PM 0
Share

Quaternion.Slerp needs to be called every frame. Your code only calls it very two seconds. Try this:

 var rotationSpeed = 2;
 var rotationStart = 0.0;
 var speed = 0.1; 
 var rotatehome = false;
 
 function Awake ()
 {
     transform.Rotate(rotationStart,0,0);
 }
 
 function Update ()
 {
     if (Input.GetButton("Fire1"))
     {
         rotatehome = false;
         
         var foo : float = Input.GetAxis("$$anonymous$$ouse X");
         Debug.Log(foo);
         
         transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("$$anonymous$$ouse X") * rotationSpeed);
         Return();
     }
     else if (rotatehome)
     {
         transform.rotation = Quaternion.RotateTowards(transform.rotation, new Quaternion(0,0,0,1), rotationSpeed);
     }
 
 }
 
 function Return()
 {
 
     yield WaitForSeconds (2.0);
     rotatehome = true;
 
 }
avatar image paco morales · Jan 15, 2013 at 10:11 PM 0
Share

Thanks Robert now is perfect :)

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

Return to the point of rotation? 2 Answers

A node in a childnode? 1 Answer

Rotation problem 1 Answer

Minimum distance on configurable joint? 2 Answers

Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 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