Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_EoQvLrO5Uh1WDA · May 22, 2018 at 04:21 PM · 2d gamescript.transform.rotationwheel

how to gradually slow down the speed of the wheel?

I'm new to Unity and trying to make a spin wheel game which works by spinning when i click and gradually slows down with time and the pointer points towards a specific segment referring to the prize.

I've a few ways to do this, like creating each segment of the circle as a rigid body and adding a fixed joint to the adjacent segment (10 in total). and putting a hinge joint in the center of a circle but it doesn't works.

next i tried something with transform.Rotate something like this.

 function Update() {
 
     if (Input.GetMouseButton(0)) {
         
         var tran: float;
         var i = 0;
 
         tran = Time.deltaTime * 10;
         transform.Rotate(0, 0, -tran);
         
     }
 }
 

it didn't worked either as the wheel only spins when i click on it, so, slowing down is not a case here too.

i saw this answer most closely related but still no help.

is it something to do with Animation? any guesses how can i achieve this?

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

Answer by Captain_Pineapple · May 22, 2018 at 04:49 PM

Hey there,

the code you provided is almost correct, you only have to pack the code a bit different:

  function Start(){
          tran = 0;
          }
 
 function Update() {
  
      if (Input.GetMouseButton(0)) {
              if(tran < 0.1f) // makes sure to only accellerate if the wheel is below a certain speed;
         {
             tran = 100.0f;
         }
      }    
      //reduce speed "tran" by 5% every frame:
      tran = 0.95f * tran;
      // rotate wheel every frame by given speed "tran"
      transform.Rotate(0, 0, -tran*Time.deltaTime);
  }

now you only have to add your variable tran as a float to your class and you should be good to go. This code should now: Accellerate your Wheel to a value, but only if its speed is below 0.1f and slowly decellerate. Please bear with me if the code is not correct in syntax, i only write in C# so javascript is really not my territory.

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 unity_EoQvLrO5Uh1WDA · May 22, 2018 at 07:31 PM 0
Share

hi, thank you so much for the reply, and yea i guess i was pretty close, however , the wheel stops pretty soon, maybe because of the constrains , maybe lowering down the multiplier might work but do you think there is a better way to achieve a bit more realistic slowing down?

I read somewhere that we can provide torque, do you think that would be good idea? thanks again!

avatar image Captain_Pineapple unity_EoQvLrO5Uh1WDA · May 23, 2018 at 09:24 AM 0
Share

well objviously the first choice would be to take the 0.95fand change it to some 0.99for something similar. The closer it gets to 1, the slower it will slow down. Obviously you could also take some linear approach.

Lets say you want it to get slower by 10 units per second. change the calculation to tran = tran - (10*Time.deltaTime). So your wheel should be at a full stop after around 10 seconds. (At this point you should include a check so that your "tran" does not fall below 0 ;))

I just personally don't like such a linear approach but perhaps it is the right thing for you :)

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

98 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 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 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 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

Need Help Push and pull script for co-op/multiplayer 0 Answers

Ragdoll toggle unity 2d 1 Answer

,Top Down Shooter Acceleration and Deceleration/velocity Movement 2 Answers

I need help making wheels. 1 Answer

How to implement a flip direction to my 2D character controller? 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