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 IronFurball · Oct 10, 2011 at 01:58 PM · rotatesmooth

make rotation smooth and instant

hi, im new to unity and have a problem with making a cube rotate,

this is the code im using and its attached to a cube:

Vector3 myRotation = new Vector3(0,0,0); bool rotate = false; void Update () {

     if (rotate)
     {
         transform.Rotate(myRotation);
     }
     switch(Input.inputString)
     {
         case "d":
             rotate = true;
             myRotation.y = 2;
         break;
         
         case "a":
             rotate = true;
             myRotation.y = -2;
         break;
         
         case "":
             rotate = false;
             myRotation.y = 0;
         break;
         
         case default (string):
             rotate = false;
             myRotation.y = 0;
         break;
     }
     
     if (rotate)
     {
         transform.Rotate(myRotation);
     }
 }

the problem is that the cube doesnt instantly, or smoothly, rotate but instead waits for about a second and then sdtarts rotating.

can anyone help me with getting this to rotate smoothly?

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

Answer by Owen-Reynolds · Oct 10, 2011 at 02:18 PM

You know how when you hold down a key, it prints once, then a delay and it prints like 20 a second? That's what Input.inputString is reading. It looks like: "d", "", "", "", "", "", "d", "", "", "d" ..... . It's more for text entry. Lots of ways to fix the problem, once you know that.

You might convert to testing if(Input.getKey("d")) (read the Input section of the scripting manual.) It's specially made to be true every frame "d" is down.

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 IronFurball · Oct 10, 2011 at 07:30 PM

Thanks for your reply :)

When I started I did use the input.getkeydown, onyl I thought it would be more efficient if I could use a switch case.

otherwise I'd have to make and if statement for getkeydown.D, then an else if for getkeydown.A and a nother if statement for if they were released :/

so should I just do that, or is there a more efficient way?

Thanks.

Comment
Add comment · Show 1 · 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 Owen-Reynolds · Oct 10, 2011 at 11:48 PM 0
Share

Can avoid checking for keyUps with clever program$$anonymous$$g (rotate if "d"d is pressed, otherwise don't.) Getting it working is #1. Once you get some experience, and know which part is slowing you down, you can try and rewrite it faster.

Also, try to avoid posting comments as answers.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

90 Degree Smooth Rotate On Button Press 1 Answer

Turn page, smooth rotate 1 Answer

OnTriggerEnter smooth Rotate 1 Answer

smooth rotate help 1 Answer

Rotate camera around object smoothly 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