Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Rigidbody keeps sliding

Discussion in 'Editor & General Support' started by snicholls, Oct 28, 2009.

  1. snicholls

    snicholls

    Joined:
    Mar 19, 2009
    Posts:
    229
    Hi all, I have a standard cube with a rigid body attached and I cannot seem to stop it moving when its resting. It always slides slightly so that if I leave the game alone for a while it will move all the way over to the other side of the screen.

    I have tried playing with the friction values etc with no luck. The platform the cube is on is completely flat.
     
    AdmiralThrawn likes this.
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Is there any script on the object that adds forces, etc?
     
  3. towcar

    towcar

    Joined:
    May 2, 2009
    Posts:
    106
    I have the same problem

    If you download the FPS Rigid Body example it comes with a demo of the Rigid bodys useage, and in the demo it automatically slides and its kinda old. Help
     
  4. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,822
    Try this.

    In the rigid body.
    Play around with its mass (try increasing it).
    Try increasing its linear dampening (which is called drag I think).

    Give it a physics materiel.

    For the physics material
    Sets its static and dynamic material to 1.0
    Also set the friction combine parameter to use maximum.
     
  5. pimpin

    pimpin

    Joined:
    Nov 11, 2012
    Posts:
    6
    to stay still
    rigidbody.kinematic = true;
    to move again
    rigidbody.kinematic = false;
     
  6. Toasttify

    Toasttify

    Joined:
    Mar 27, 2012
    Posts:
    143
    Don't do that unless you feel like constantly having to awaken rigidbodies from their kinematic state.

    Also this thread is 4 years old so he probably found a solution already...
     
  7. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,097
    Maybe, but I have the exact same problem as the OP. In fact I have temporarily abandoned the game idea because of it. No mater what I did to the moving object and the resting surfaces the moving object would either wobble off or slide off. I tried huge mass, materials I even tried the turning off kinematic which worked best BUT the logic to try and decide when to do that made it temperamental.

    So I too would like to know how best to achieve this. I have a great game just sat in a directory waiting for the answer.
     
    TommyDoomsday likes this.
  8. meat5000

    meat5000

    Joined:
    Mar 5, 2013
    Posts:
    118
    I'm having the same trouble. This thread was started in 2009. It's 2013 now and still no answer to this widespread problem? A lot of projects have been abandoned for this rigidbody sliding and bouncing defect.
     
  9. acorrow

    acorrow

    Joined:
    Jan 4, 2015
    Posts:
    32
    Yes I know this is a bit of a necro, but hey, someone resurrected this from 4 years in the grave so.....

    I ran into this seemingly out of no where, and did a bit of searching then had a "DOH!" moment. Make sure that your rigid body isn't a Child of your camera, and the camera set to follow the ridigbody. This is what happened to me. I was organizing all my Levels "standard" objects into one game object, and accidentally made the character a child of the camera I setup to follow it. This will constantly "slide" your character based on the last movement speed.

    Hope this helps someone
     
    TheTrueAlpha and BrandyStarbrite like this.
  10. TheButtaSauce

    TheButtaSauce

    Joined:
    Apr 12, 2014
    Posts:
    8
    Figured this out.

    Change the following settings in your projects physics settings.

    Edit > Project Settings > Physics

    Solver Iteration Count: at least 10 (I use 15)
    Enable Adaptive Force: On (I turn this on, although it isn't necessary)

    Hope this helps! ^_^
     
    kk3hi3123 and GeminiGamer like this.
  11. GeminiGamer

    GeminiGamer

    Joined:
    May 23, 2015
    Posts:
    1
    Hey, this works...!!!! Thanks a lot. Was stuck on this for hours. :D
     
  12. Datapax

    Datapax

    Joined:
    Sep 10, 2015
    Posts:
    4
    Hi all, I know this is pretty old but, for anyone like me that may end up here, there is another thing you can try that I didn't find in the posts above.

    So, if you are still here and nothing worked, check if you have <AnimationController> component attached to your object. If you have - disable it and try to run the game. If the issue disappears you should check and change the settings of your animations controller and/or animations!

    It worked for me.
     
  13. bigoMay

    bigoMay

    Joined:
    Sep 14, 2013
    Posts:
    6
    Hello all,

    I had a similar problem with RigidBody objects. In my case, the problem was that the surface where the objects were resting had a MeshCollider, which for some reason was producing a slight sliding of the objects. Changing the collider of the surface to a simple BoxCollider fixed the problem.

    I am not sure about the reason for this, but my guess is that the MeshCollider was overloading the physics engine with too many precise calculations, resulting in the sliding on the objects.
     
  14. Dier0

    Dier0

    Joined:
    Jan 2, 2017
    Posts:
    1
    Hi all,
    I made script for moving platforms, not by changing position, but moving it. This fixed sliding problem and moving is sinusoidal.

    It worked for me.
     

    Attached Files:

  15. day_of_money

    day_of_money

    Joined:
    Feb 26, 2015
    Posts:
    1
    I know this is super late however i ran into this problem as well and could not find the answer because none of the above worked for me so i keep searching and find an idea on how to fix this problem. and with that in mind this is what i came up with to fix it.
    Hope it helps.
     

    Attached Files:

    AdmiralThrawn likes this.
  16. GGLio

    GGLio

    Joined:
    Apr 30, 2017
    Posts:
    1
    just increase the linear drag and increase the speed
     
    MurFiesta likes this.
  17. MurFiesta

    MurFiesta

    Joined:
    Jun 18, 2017
    Posts:
    1
    I ran into this issue building the space shooter tutorial. I increased the drag to 10 and the speed to 200 and that solved my issue - thanks GGlio/ others who provided the same advice.
     
  18. Ojiba

    Ojiba

    Joined:
    Aug 18, 2017
    Posts:
    1
    I think i have finally solved this. I was having the same issue and racking my brain about it. Turns out it was way too simpler. are you using the default 2d asset platforms? If so, the default 2d asset platforms have an attached collider set to be slippery, just turn that off.
     
  19. AdmiralThrawn

    AdmiralThrawn

    Joined:
    Dec 1, 2013
    Posts:
    18
    I'd like to add my case just in case another developer has a similar problem like me:

    If you have a gameObject with a spherical collider (e.g. with frozen x- and y- axes but the y axis remains unconstrained) and you got a 2d sprite on it which - like in my game project - is facing itself to the camera (via script), then your GO will slide after any movement IF you have no angular drag on the rigidbody component! Setting it to 1 eliminated that problem.

    Here a picture to visualize the problem I had.
     

    Attached Files:

    katesutt1, ManuelCosta and ZeldaSpace like this.
  20. VasileQ

    VasileQ

    Joined:
    Jan 12, 2018
    Posts:
    1
  21. ultraroar101

    ultraroar101

    Joined:
    Jun 16, 2017
    Posts:
    2
    If you are using a capsule or sphere collider, don't. Perform the movement on a box collider and if you still want to use a capsule/sphere collider afterwards, but ensure that the box collider is always covering the base of the character. I have found that the rotation is due to the friction on the ground.
    Just don't use a capsule collider.
     
    xlilcoachx likes this.
  22. GameEverything

    GameEverything

    Joined:
    Feb 22, 2016
    Posts:
    8
    This is the oldest thread ever, lol. Anyway, I fixed the same problem rather quickly by using a physics material on both the ground and player where I then changed the friction on both. I remember having this problem like five years ago and it was reminiscent of the ice levels in almost every old school NES game; Battletoads, Mario 3, etc. Those were the days.
     
  23. ZeldaSpace

    ZeldaSpace

    Joined:
    Jan 21, 2018
    Posts:
    2
    Adding those constraints you show in the picture fixed my problem. Thanks!
     
  24. contact_sachin

    contact_sachin

    Joined:
    Apr 19, 2018
    Posts:
    1
    your plane on which rigidBody is resting has non uniform scale along x and z axis.
     
  25. Samupo

    Samupo

    Joined:
    Dec 2, 2017
    Posts:
    1
    I know this is an old post but it's the first one that appears in Google when you search for the problem so I'm sharing my solution here.

    Quick and easy: put gravity scale to 0 when the object is grounded, reset it to your like whenever it's not.

    This has worked for me in 2D, haven't tested in 3D yet.

    To find if the object is grounded I get the collisions and check normals, I'm using y > 0.5f because I don't want any sliding. I keep a list of all the floors the object is colliding with, adding and removing them as the object enters or leaves the collisions. When no floors are present I just assume it's either jumping or in free fall and reset gravity.
     
    sourbacon likes this.
  26. Aeroxima

    Aeroxima

    Joined:
    Jul 19, 2016
    Posts:
    9
    Alright so I just spent so many hours on this today and nothing above helped, but I figured out what my problem was:

    I just had to change from using Input.GetAxis() to Input.GetAxisRaw()

    Basically GetAxis is applying smoothing. Went through hell to figure this out, doing all kinds of tests and implementing the same things a ton of different ways, thinking it's crazy how my code has told it to teleport and stop and it keeps sliding after all buttons had been let go.

    I never suspected the part that would be messing it up would be the "direction to move" variable.
     
    VodViet likes this.
  27. yoyo696

    yoyo696

    Joined:
    Aug 11, 2015
    Posts:
    14
    Best Answer was increasing the linear drag. Thx <3
     
  28. jaredgregersen

    jaredgregersen

    Joined:
    Nov 24, 2018
    Posts:
    1
    [¬º-°]¬

    An option that worked for me (for a player controlled 2D object w/rigid body that kept sliding) was to alternate between a speed variable that is a positive integer value during desired movement, and a value of 0 (when needing to stop without sliding).

    For example, assuming Speed is defined as a positive integer (such as 1, 2, etc...) and used in determining desired movement speed (while checking for key input, in Update() ):



    //Movement
    if (Input.GetKeyDown("a"))
    {
    speedtmp = Speed;
    ...



    //Movement Stop
    if (Input.GetKeyUp("a"))
    {
    speedtmp = 0;
    ...


    The variable speedtmp can then be used in conjunction with the rigid body .MovePosition method, within FixedUpdate(), for determining rigid body position:

    rigidBody.MovePosition(rigidBody.position + inputs * speedtmp * Time.fixedDeltaTime);


    When speedtmp = 0 , this results in the above line of code also equaling 0, stopping the rigid body position at the current position (without sliding further).
     
  29. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    15
    I realize this question was posted in 2009, but for any one that needs help, I tried playing with the Angular Drag on the Rigidbody component. I set the value to 100 and it fixed my issue. Hope I help someone.
     
  30. shwa

    shwa

    Joined:
    Apr 9, 2012
    Posts:
    443
    Same problem here. Trying lots of fixes. Still sliding.

    This is inane.

    Unity should chime in and offer a solution, asap.
     
  31. pokruchin

    pokruchin

    Joined:
    Apr 24, 2019
    Posts:
    1
    This is the only answer, that solved my issue for 95%. But in my case I had to set not 10 or 15 but 50.
    Thank you from 2019!
     
  32. mikeKB

    mikeKB

    Joined:
    Jan 7, 2018
    Posts:
    1
    If you're not planning on having any outside forces moving the player horizontally (explosions, sloped angles where the player slides, etc.), you could do something similar to:


    Code (CSharp):
    1. if (!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D)) {
    2.     rb.velocity = new Vector2(0, rb.velocity.y);
    3. }
     
  33. copperhaxor55

    copperhaxor55

    Joined:
    Jul 15, 2018
    Posts:
    2
    Code (CSharp):
    1.     public void Move()
    2.     {
    3.         playerGameObject.transform.forward = virtualJoystick.heading;
    4.         thisRigidBody.transform.forward = virtualJoystick.heading;
    5.         thisRigidBody.position += virtualJoystick.rightMovement * playerMovementSpeed * Time.deltaTime;
    6.         thisRigidBody.position += virtualJoystick.upMovement * playerMovementSpeed * Time.deltaTime;
    7.     }
    This was triggered by the following (causing a slide, regardless of what settings i put in rigidbody)

    Code (CSharp):
    1.         if (virtualJoystick.heading != null)
    2.         {
    3.             Move();
    4.  
    5.         }
    Changed to this and now works.

    Code (CSharp):
    1.         Vector3 MoveVector = virtualJoystick.heading;
    2.         if (MoveVector != Vector3.zero)
    3.         {
    4.             Move();
    5.         }
     
  34. VodViet

    VodViet

    Joined:
    Feb 24, 2018
    Posts:
    1
    Thank you very much, this helped me alot! :D But i spent many hours, too. :(
     
    Aeroxima likes this.
  35. leglegarmhead

    leglegarmhead

    Joined:
    Nov 10, 2019
    Posts:
    3
    I'll just add on to this, there's so many solutions but just turning off GravityScale (setting it to 0) for the sliding object worked for me.
     
  36. michaelday008

    michaelday008

    Joined:
    Mar 29, 2019
    Posts:
    13
    After struggling with this for several hours here was how I fixed the issue:

    Code (CSharp):
    1. rigidBody.interpolation = RigidbodyInterpolation.None;
    2. rigidBody.detectCollisions = false;
    3. rigidBody.isKinematic = true;
    It seems that Unity has a bug (or unwelcome "feature") that turning your rigidbody to kinematic still allows it to experience physics unless RigidBodyInterpolation is set to None. Even completely disabling colliders on your component does not help.

    The worst part is the failures are silent and I only discovered this after desperately trying every single setting.