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 michellejean · Feb 06, 2014 at 09:11 AM · quaternionrotate object

Changing the speed of a rotating object

I am making a game in which I have a turret which rotates. Originally I had code which made it work but the speed was too slow:

         //transform.parent.rotation = 
         //    Quaternion.AngleAxis(currentAngle + (Time.deltaTime * rotationDegreesPerSecond), Vector3.forward);


Based on this question link text I changed my code to this:

 rotationDegreesPerSecond = 90f
 
 transform.parent.rotation = 
             Quaternion.Slerp (transform.parent.localRotation, Quaternion.AngleAxis(currentAngle + (Time.deltaTime * rotationDegreesPerSecond), Vector3.forward), Time.deltaTime * 2000000);

Now what I don't understand is where I have Time.deltaTime * 2000000. When I had it at Time.deltaTime *3 it rotated really slowly. But when I increased the number the rotation speed increased as well. Unfortunatly eventually it stopped speeding up no matter how high I put the number. It is now rotating about as fast as my original code but I need it to rotate about twice as fast or faster (currently approx 4 seconds for a full 360 degree rotation).

I would really appreciate it if someone could explain to me how to fix this or else explain a different way to do this.

thanks, Michelle

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 michellejean · Feb 06, 2014 at 10:53 AM

Ok I figured it out. This is my new code:

 float rotateSpeed = 5f;
 void Update(){
     rotateCounterClockwise();
 }
 void rotateCounterClockwise(){
     transform.parent.Rotate (Vector3.forward, rotateSpeed);
 }


I was obviously way over complicating it.

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
1

Answer by robertbu · Feb 06, 2014 at 09:30 AM

I cannot give you and exact answer on what you should be doing without see more of your turret code, but I can point out some strangeness in your current code. The first parameter of your Slerp uses 'localRotation' but you are assigning 'rotation'. Depending on your use, they both should match. But because of the next issue, the use of localRotation is a non-issue since the first parameter is never used.

The second issue is how you are using your Slerp(). Used this way, the last parameter must be a fraction of 1.0. Anything above 1.0, and the code simply assigns the second parameter. In other words, your code is the same as:

 transform.parent.rotation = Quaternion.AngleAxis(currentAngle + (Time.deltaTime * rotationDegreesPerSecond)); 

That is the Slerp() is not used and the second parameter is just getting assigned. With this in mind, you can speed up your rotation code by changing the 'rotationDegreesPerSecond' parameter. Without seeing the rest of your turret code and have a understanding of your setup, I cannot go further in recommending a solution. I expect the 'right' solution when you get things sorted out will use Quaternion.RotateTowards() instead of Slerp().

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 michellejean · Feb 06, 2014 at 09:52 AM 0
Share

That actually is pretty much my entire script. The game objects are already in the scene and I just dropped the script on them. There are two of them and they both rotate as I planned just really slow. The code I posted here is currently in the update method, although I will be changing that eventually.

avatar image michellejean · Feb 06, 2014 at 10:06 AM 0
Share

I changed the code to use Quaternion.RotateTowards();

 transform.parent.rotation = Quaternion.RotateTowards(transform.parent.rotation, Quaternion.AngleAxis(currentAngle + (Time.deltaTime * rotationDegreesPerSecond), Vector3.forward), Time.deltaTime * 400f);

Unfortunately I'm having the same problem. Changing the amount Time.deltaTime is multiplied by changes the speed of the rotation, however after a certain point it never gets any faster.

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

18 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

Related Questions

Change rotation of an object based on an HTC Vive Controller 1 Answer

Choose starting point/angle for rotation with cos and sin 0 Answers

What Should i use rigidbody.AddTorque() or Quaternions ? 1 Answer

Problem with Quaternion.LookRotation() 1 Answer

How to rotate an object depending on the rotation of an other Object 3 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