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
1
Question by FallingThroughSpace · Jul 15, 2018 at 05:14 PM · rotationmovementfrictionridgidbody

Friction seems to be slowing my rolling ball instead of helping it accelerate. How to improve my rotation-based movement?

In real life, the friction between a car's tyre and the road is what gives the car the power to accelerate forward. I tried to go for a similar situation in the "game" I'm working on, having a sphere that rotates itself in order to move. However, instead of gaining speed, it accelerates at first but then seems to hit a ceiling and wont go any faster.

.

Initially I was using AddForce in order to make the ball move. It was looking good, but I wanted something more genuine/realistic so I experimented with AddTorque only and both. The speed limit was present in all those situations. Something I did notice about AddTorque that I didn't like was how even in mid-air or in a no-friction environment it would have a rotation speed limit, instead of keep adding to the angular momentum as I would expect. If there is a better way to add angular momentum to a ridgidbody, I'd be glad to hear.

.

Naturally I'm aware that maybe there is something wrong with my code:

 using UnityEngine;
 
 public class BallMovement : MonoBehaviour {
 
     public Rigidbody rb;
     public float moveForce = 1000f;
     public float rotForce = 2500f;
     void FixedUpdate ()
     {
         if (Input.GetKey("d"))
         {
             rb.AddForce(moveForce * Time.deltaTime, 0, 0);
             rb.AddTorque(Vector3.back * rotForce);
         }
         if (Input.GetKey("a"))
         {
             rb.AddForce(-moveForce * Time.deltaTime, 0, 0);
             rb.AddTorque(Vector3.back * -rotForce);
         }
         if (Input.GetKey("w"))
         {
             rb.AddForce(0, 0, moveForce * Time.deltaTime);
             rb.AddTorque(Vector3.right * rotForce);
         }
         if (Input.GetKey("s"))
         {
             rb.AddForce(0, 0, -moveForce * Time.deltaTime);
             rb.AddTorque(Vector3.right * -rotForce);
         }
     }
 }
 

.

The ridgid body is a sphere that is set to move and rotate freely. My angular drag is at 0, the only object that really has a physics material is the ball itself with 1.5 in each type of friction. I'm pretty sure the problem IS the friction but I have no clue how to get around it. If I tone it down it does accelerate with AddForce but it also gets very slippery. If I turn it off movement through rotation only impossible.

.

I'm just a beginner so any help is greatly appreciated. And it might be rude to ask a bonus question but it's semi-related:

What is the best way to "break" the angular momentum of an object? I want to bind the shift key to a break that helps the player stop rotating in case standing still is needed, I'm not aware of any way of making it happen other than figuring out how much the object is rotating in a certain axis, then applying an opposite rotation force until the rotation is 0, but that is probably overcomplicating it. My searches were fruitless, probably because I'm not familiar with the name of things yet.

Thanks in advance.

Comment
Add comment · Show 1
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 Harinezumi · Jul 16, 2018 at 11:29 AM 0
Share

I'm not sure, because I haven't used it before, but Rigidbody has a maxAngularVelocity field that limits angular velocity. As the scripting reference states, this value is set to 7 by default (because why not?), which "may prevent intentional fast rotations on objects such as wheels".
(Note that previously you could set it with Set$$anonymous$$axAngularVelocity(), but at least in Unity 2017 this is deprecated)

But there is also such a thing as a WheelCollider, which probably is better suited for your use case (but unfortunately, I can't help with that, because I've never used it).

And I guess I would brake the wheel by modifying Rigidbody.angularVelocity, or applying a strong torque in the other direction, then clamping, so that braking doesn't start to drive in the other direction.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by J-F · Jul 16, 2018 at 09:09 AM

Angular drag only affects rotation, Try tweaking the linear drag value in the rigidbody component, usually just labeled as "drag".

Comment
Add comment · Show 3 · 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 FallingThroughSpace · Jul 16, 2018 at 11:05 AM 0
Share

Not the problem. It still accelerates like I want with the drag I was using (0.1) and no friction. But it doesn't when I remove the drag and go with normal friction. While high enough drag does limit the "ter$$anonymous$$al velocity" for any given force added, I don't think it is the culprit since the undesired effect is still there when the drag is not. Thanks for your input!

avatar image J-F FallingThroughSpace · Jul 16, 2018 at 12:09 PM 0
Share

How fast is the ball actually spinning? Does it spin insanely fast and just skid in place?

avatar image FallingThroughSpace J-F · Jul 16, 2018 at 02:38 PM 0
Share

Not as fast as I'd hope. As I said, there is a limit to how fast it spins, its rotation stops accelerating at some point and it's way slower than what I'd like. Actually I would like the rotation to keep increasing as long as the force was still there. It only skids in place if I turn of friction and use AddTorque only, ins$$anonymous$$d of AddForce or both.

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

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

rotation speed cap in 2D 0 Answers

Rotation used as movement 4 Answers

Joystick for WASD & Joystick for Camera? 0 Answers

Stop camera from moving when parent rotates forward 1 Answer

3D Heat Seeking Missile (C#) - Odd problem 1 Answer


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