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 /
This question was closed Nov 10, 2014 at 12:51 PM by bobin115 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by bobin115 · Nov 10, 2014 at 10:22 AM · rotatesmooth

smooth rotate help

i have a script when you collide with an object and press a key it rotates. however it rotates instantly and i want it to do i smoothly. here is my script:

 function OnTriggerStay(trigger : Collider) {
      if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.E)) {
          transform.Rotate(0, 10, 0 * Time.deltaTime);
      }
 }

how would i make it rotate smoothly?

thanks

Comment
Add comment · Show 2
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 Hoeloe · Nov 10, 2014 at 10:28 AM 0
Share

First it might help if you weren't multiplying Time.deltaTime by zero. What happens when you multiply a number by 0?

avatar image bobin115 · Nov 10, 2014 at 10:44 AM 0
Share

how would i add a value to time then?

1 Reply

  • Sort: 
avatar image
1

Answer by DaDonik · Nov 10, 2014 at 10:50 AM

 function OnTriggerStay(trigger : Collider) 
 {
     if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.E)) 
     {
         transform.Rotate(0.0f, 10.0f * Time.deltaTime, 0.0f);
     }
 }
 


If you need it slower, just replace 10.0f with a lower value.

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 bobin115 · Nov 10, 2014 at 11:14 AM 0
Share

at the moment it moves in sharp jolts "0,0,0" are just how much it rotates on an axis. i would like it to rotate smoothly

avatar image Hoeloe · Nov 10, 2014 at 11:25 AM 0
Share

We know. But by multiplying the rotation by deltaTime, which is the time in seconds since the last frame, the motion becomes framerate independent. This makes the motion "smooth". If this isn't what you're looking for, then it would be helpful if you could clarify what you mean by "smooth", because it's a very vague term.

avatar image DaDonik · Nov 10, 2014 at 11:27 AM 0
Share

Oh well, i wasn't thinking before posting, sorry. One way you can achieve what you want to do is by setting a variable inside the OnTriggerStay and then rotate your object in the Update function. Like so:

 var Rotate$$anonymous$$e = false;
 var RotateSpeed = 10.0f;


 function Update()
 {
     if (Rotate$$anonymous$$e == true)
     {
         transform.Rotate(0.0f, RotateSpeed * Time.deltaTime, 0.0f);
     }
 }

 function OnTriggerStay(trigger : Collider)
 {
     if ((trigger.gameObject.tag == "Player") && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
     {
         Rotate$$anonymous$$e = true;
     }
     else
     {
         Rotate$$anonymous$$e = false;
     }
 }

RotateSpeed will be in degrees per second in that case.

I'm not using Unityscript normally, so i'm not 100% sure thats all correct, but it should be.

avatar image bobin115 · Nov 10, 2014 at 12:51 PM 0
Share

all i had to do was tweak one thing and it worked

cheers

Follow this Question

Answers Answers and Comments

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How can i make my aircraft rotate as smooth as the one in race the sun, and then go back to its original position 1 Answer

Door rotate on hinge 1 Answer

Animation spins wildly after completed 0 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