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 nowarelabs · Jan 10, 2012 at 05:47 PM · torquerigibody

Rolling ball with rigidbody

I'm trying to make simple ball game where player is supposed to roll a ball. I get ball rolling, that's not a problem but I'm unable to make it "speed up".

My current code looks like this:

 void update() {
     force = Vector3(Input.GetAxis("Horizontal") * maxspeed * Time.deltaTime, 0, Input.GetAxis("Vertical") * maxspeed * Time.deltaTime);
 } 
 
 void fixedUpdate() {
     rigidbody.addTorque(force);
 }

This works so that ball accelerates quite quickly to maxspeed and stays there. But I would like to speed up more when axis button is kept pressed for longer times. How I can achieve that?

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 syclamoth · Jan 10, 2012 at 09:06 PM 0
Share

Time.deltaTime inside of Update is different from the Time.deltaTime in FixedUpdate- if you create the value in one, it'll be wrong in the other!

avatar image arcghost · Jan 10, 2012 at 10:39 PM 1
Share

It still records the time the key is pressed, so it doesn't matter. 1 second in update is the same as 1 second in fixedupdate. I advice to use it in Update() because that function is called more often so results would be more accurate.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by arcghost · Jan 10, 2012 at 07:34 PM

You will have to record the time the keys are pressed. You can use an if-statement to check if a key/axis is pressed and Time.deltaTime to check how much time passed since the frame is complete.

 void Update () {
     if( Input.GetAxis(" --the axis you want to check-- ") != 0 ){
         timePressed += Time.deltaTime; //make a new var to keep track of the time.
         increaseMultiplier();
     }
     else{
         timePressed = 0; //The button is not being pressed anymore.
         decreaseMultiplier();
     }
     
 }

You will have to make a multiplier variable to apply to the speed of the object and adjust that value. I hope this helps.

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 nowarelabs · Jan 12, 2012 at 08:36 PM 0
Share

Thank you, this got me on right track. I had to change code a bit from using torque to applying force due limitation in angular velocity. I tried to set higher angular velocity limit but it creates unwanted rotation.

avatar image
0

Answer by nowarelabs · Jan 11, 2012 at 02:55 PM

Apparently rigidbody has defined maximum angular velocity (7 by default). I can change it but then feeling of rotation is something that I do not want.

Maybe I should use force (not torque) and do rotating ball using transform?

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Guided Missile 0 Answers

Physics object slides while turning. 1 Answer

Problem with joystick movement 1 Answer

Addtorque towards a point, compensate for its inertia? 0 Answers

Adding torque on an object's axis 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