- Home /
Rigidbody unwanted drifting
Hi everyone! yet another question on physics stuff...
I've got a simple scene with a cube and a plane. The cube has a box collider and a rigidbody attached while the plane has just a mesh collider attached.
I made a simple script to make the cube slide on the plane, according to user input, that only applies forces to its rigidbody. I used the following code to make it move on its forward direction:
float vaxis = Input.GetAxis("Vertical");
rigidbody.AddRelativeForce(speed * vaxis * Vector3.forward);
Drag and angular drag are set to zero.
Since there are no physic materials attached to any object in the scene and the physics settings are set to default values, I would expect the cube to slide in its forward direction without changing its orientation but this is not what I get. Its rotation params slightly change and the result is that the cube is not moving straight forward, but is following a curved trajectory on the plane that I can not control.
If gravity is disabled on the cube or if I freeze rotation, everything works as expected but this is not a solution in my case. Why is this happening? Am I missing something in the way rigidbody or physics works?
Any help is appreciated!
EDIT -----------
I forgot to mention that I set the cube's rigidbody center of mass to (0, -1, 0) to make the cube slide and not roll...
Answer by Noob_Vulcan · May 21, 2014 at 12:06 PM
Yes this effect is very much expected (basic Physics). The friction force is making the cube to rotate. So you have two options
1.Freeze Rotation
2.Add a physics material( set friction to 0 and rest options to minimum) and the material to box collider (i.e cube ).
Thank you for your answer, I'll try to play with physic material then...
But still I do not understand where the friction force come from... maybe it is generated from the interaction between the cube's box collider and the plane's mesh collider even if I do not assign any physic material to them.
@dumby Yup u are rite it is generated from the interaction between the cube's box collider and the plane's mesh collider. If my answer helped you then mark it as answer so that if any body else run into same problem then he can refer to this answer. Thank you
Yep. After some other experiments I can say that there is definitely some kind of friction between colliders even if none of them has a physic material assigned. I run into this problem because the docs say:
Friction, bounciness and softness are defined in the Physisc $$anonymous$$aterial.
which is not totally correct as far as I can tell...
Thank you!
Welcome..When ever you add rigidbody to some object physics is applied i.e some friction force starts acting (by default). To make it frictionless u have to add something extra i.e physics material
Answer by rkatos · Apr 16, 2016 at 08:32 PM
I've run into this problem and yes, setting dynamic friction to 0 stops it, but this is not accurate to the real world.
I also seems the higher the friction the more forceless sliding takes place. Again, opposite to what one would expect!
Answer by R1P4R14N · Feb 02 at 03:51 AM
This was my problem.
Another solution is to put a rectangular collider on the bottom part of the object so that it doesn't spin. At least that's what worked for me. Yes I realize this is 6 years old but hey if I'm reading it someone else will be too. Good luck!
Your answer
Follow this Question
Related Questions
Movement on a tube 1 Answer
Change Gravity? Physics scaling for large objects to behave like normal ones... 0 Answers
Attaching Rigidbody breaks gravity 1 Answer
Gravitational Object Creation for 3D Game 1 Answer
gravity problem 1 Answer