- Home /
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.
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.
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".
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!
How fast is the ball actually spinning? Does it spin insanely fast and just skid in place?
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
Follow this Question
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