Hi everyone! I’m currently working on a car controller script using a sphere rigidbody and AddTorque for movement, and want to design it in such a way where the values are accurate and easy to understand for the player. With an acceleration of 10, to get to a speed of 40, takes 4 seconds.
Both the drag and angular drag of the rigidbody are set to 0.
When the motor is in the air without gravity and contact with a surface, this works perfectly. However when it’s rolling along a surface, it slows significantly to close to 3/4 times slower.
If I multiply the torque by roughly 3.5 it brings it close to the intentional behaviour, but I would rather know where this value and the slowing is coming from so I can remove it. My only guess is it’s caused by the friction but friction shouldn’t affect a smooth sphere on a flat plane. If friction is the case, with a 0 friction material the ball can’t roll, so I don’t know how to make the sphere move without directly changing the velocity, which I want to try to avoid.
So far I’ve tried:
Changing the strength of gravity and the mass of the rigidbody, neither of which affect the acceleration.
Decreasing the friction to prevent it from affecting the sphere, but this just made the ball slip and slow down further.
Increasing the friction to prevent slipping, but the speed is unaffected.
I have some workarounds but I’m more just curious what’s causing it. If anyone has any idea I’d love to hear suggestions, and if you need more info about what I’ve worked on so far I’d be happy to let you know.
I don’t understand your problem. Your task is to “design it in such a way where the values are accurate and easy to understand for the player”. And your problem is that your car speed slows down when on a surface, as opposed to being in the air? I mean, test it at home, take a random object and throw it to the wall, you’ll see that it slows down once it hits a surface and won’t travel through the wall.
What are you trying to achieve, and what is the problem?
Sorry, I was trying to get as much info about the problem but I realise I could have been a bit clearer on the actual problem.
So I have a ball, and I’m applying torque as an acceleration to make it roll. When its in the air without gravity, its angular acceleration is as expected, but when it’s rolling along a surface with gravity the angular acceleration is about 3/4 times slower. Theres no drag affecting it, friction shouldn’t affect it, and I’m using ForceMode.Acceleration so mass isn’t a factor. I’m wondering where the slowing is coming from.
What is your object? You said car controller, are you having a ball or a car? An object can have only 1 rigidbody, and for some reason you have it somewhere down the hierarchy, it would typically be on the top of hiearchy. Cars typically use WheelColliders like this.
Its a sphere rigidbody. I’m using a method like this twitter post: x.com.
The body is the car attatched by a configurable joint, however the problem persists with only the motor sphere active.
I’ve isolated everything about the sphere and the slowing still occurs. Even creating a completely new separate sphere and applying the torque causes it to slow along a surface.
What does this mean? You are applying acceleration by adding angular force in the mode of acceleration. So you know what the angular acceleration is. What do you mean that “the angular acceleration is slower”? What are you measuring here? Velocity? AngularVelocity?
Ah you actually said it in your heading, angular velocity gets slowed. Just getting confused with the terms here.
So, ForceMode.Acceleration adds acceleration in a way that’s irrespective of mass, meaning that if your ball weighs 1kg or 1000kg, it will increase its rotation the same. But this doesn’t mean that the angular velocity (how fast the ball is actually spinning) will be the same, because this will be affected by the mass of your ball being pushed against the surface by gravity.
public class Motor : MonoBehaviour
{
private Rigidbody rb;
private void Awake()
{
rb = GetComponent<Rigidbody>();
rb.maxAngularVelocity = 1000;
}
private void FixedUpdate()
{
rb.AddTorque(Vector3.right, ForceMode.Acceleration);
if (rb.angularVelocity.magnitude >= 10)
{
Debug.Log(Time.time);
}
}
}
If I play, the time logged is 10, which makes sense. If I accelerate at 1 radian per second per second, it takes 10 seconds to accelerate to 10 radians per second.
If I enable Use Gravity and play again, the time logged is 34.99. It is now taking 35 seconds to accelerate to 10 radians per second, so the acceleration is a lot slower.
Yeah that was my understanding, but a smooth sphere on a flat plane shouldnt have friction as it is only a single point of contact. So I’m under the assumption that being pushed against the surface shouldn’t have an affect. Unless there’s something I’m missing.
I’m not a 3D physics dev but I would also ensure that you’re using continuous col-det in-case energy is being affected by the overlap solving/correction etc because after all, it’s a game simulation only, not a super accurate scientific one.
Additionally, to verify the forces/impulses involved, you can inspect the solver impulses for the contacts you assume are happening in OnCollisionEnter and OnCollisionStay: Unity - Scripting API: Collision.impulse
Well, having zero friction is not physically possible when surfaces are in contact. So if your PhysicMaterial says friction=0, this doesn’t mean that the physical friction between these objects is zero.
You can test this by lubricating a bowling ball and setting it to spin on ice. If what you believe is true, that the friction is zero, then it should spin indefinitely.
Maybe I’m not reading the OP correctly but a zero friction isn’t being used here correct? That was mentioned that if torque was applied, zero friction would mean that no linear movement would occur which is correct.
If the OP wants zero friction but linear movement then they can obviously use AddForce but with zero friction, no rotation would occur.
I think I’m a little lost now on what the problem is.
Yeah sorry, its hard to really explain what im after. There is friction on the sphere else it wouldn’t roll. All I’m saying is that it shouldn’t have an effect on slowing down the sphere as far as I’m aware. Is this just where my understanding is incorrect? I come from a more physics/maths background so if this is just a difference with game engines that might be what is causing confusion.
Also even with continuous collision detection the same occurs.
Both incorrect. The ball would roll obviously without friction, as it will roll in the air, it just wouln’t gain velocity because the frictional force wouldn’t translate to forward momentum. Secondly, friction obviously has everything to do with the ball slowing down. Friction is proportional to the weight that pushes these surfaces together, ie gravity and mass in this case.
You also mentioned that the ball has a single point of contact - this actually doesn’t affect friction much. It affects a tiny bit.
That I think is where game engines differ. In reality friction would not have any effect slowing the ball on a perfect surface as the movement of the ball is not moving relative to the point of contact. But assuming that is the case, wouldn’t increasing the friction of the physics material of the surface and ball, then slow the ball further? Doing this in my project yields no change.
Instead of arguing about the meaning of friction, this page will likely be your best source.
"Friction uses the coulomb friction model, which is based around the concepts of 2 coefficients: the static friction coefficient and the dynamic friction coefficient (sometimes called kinetic friction). Friction resists relative lateral motion of two solid surfaces in contact. These two coefficients define a relationship between the normal force exerted by each surface on the other and the amount of friction force that is applied to resist lateral motion. Static friction defines the amount of friction that is applied between surfaces that are not moving lateral to each-other. Dynamic friction defines the amount of friction applied between surfaces that are moving relative to each-other.
The coefficient of restitution of two colliding objects is a fractional value representing the ratio of speeds after and before an impact, taken along the line of impact. A coefficient of restitution of 1 is said to collide elastically, while a coefficient of restitution < 1 is said to be inelastic."
Thanks! That’s a lot of really interesting info, I’ll have a read through hopefully it’ll clear up my understanding. Thanks for taking the time to help me out, appreciate it!