Search Unity

Why is my Rigidbody Ball not rolling on contact with Terrain?

Discussion in 'Physics' started by JanDawid, Jun 25, 2015.

  1. JanDawid

    JanDawid

    Joined:
    Jul 7, 2014
    Posts:
    283
    Basically I have a ball being pushed around (forward, back and up) via forces on mouse clicks. Whenever the ball is at a higher speed and bounces off any terrain, it doesn't roll in reaction to the collision, it only rolls from the terrain at lower speeds, when the ball isn't bouncing off the terrain. Is there a problem with my settings or is it just the way Unity works?

    I've made a video showcasing the problem in action as well as the settings for everything relevant (ball, physics material and physics settings).

     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I am not completely sure, but it might have something to do with continuous dynamic collision detection. From what I think I have read in the past is that continuous dynamic kind of messes up the physics calculations and focuses more on keeping your object from going through things. And based on what unity said about physx3, continuous dynamic doesnt activate until a certain velocity, which might be why at low velocities you are seeing it roll.

    If you put this script on your ball
    http://wiki.unity3d.com/index.php?title=DontGoThroughThings
    and you put your collision detection to discrete, does it fix things? Maybe try putting a kinematic rigidbody on your mountain and setting its collision detection to continuous, does that change anything?
    What is your fixed timestep at? (project settings -> time) If it is at .02 and you put it to .01, does it fix things?
     
    Last edited: Jun 25, 2015
    JanDawid likes this.
  3. JanDawid

    JanDawid

    Joined:
    Jul 7, 2014
    Posts:
    283
    Doing everything you've mentioned has brought me a step closer to this working, but at the moment it's only rolling on touch about 85% of the time (before I'd say it was about 20%). It's working almost always when the ball doesn't horizontal ground but when it scrapes walls it's only working some of the time now. Playing around with different combinations of the settings you've suggested, I conclude that changing the fixed timestep doesn't change anything; giving the terrain a rigidbody (and making it static I assume meant marking it as 'is kinematic' and having the terrain as a whole a static object, right?) and setting the detection to continuous seems to have made the biggest change. This lead to the ball going through it a lot so, attaching the given script and setting collision detection to discrete has stopped the collision problem and improved the friction when scraping by the terrain.

    It's not perfect but it's much better than before. Thank you! Let me know of any more suggestions! :D
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Maybe play with the physics material on the mountains. Also in your physics settings, set default contact offset to .01 Maybe that will help the ball get closer to the walls. Also, maybe disable interpolation on the ball to see if that does anything. Other than that, I don't got much else at the moment ^^

    And yes, I meant making it a "isKinematic" rigidbody, I will edit my post to fix that ^^
     
    JanDawid likes this.
  5. JanDawid

    JanDawid

    Joined:
    Jul 7, 2014
    Posts:
    283
    Changing the default contact offset from 0.05 seems to have made this work almost perfectly! I say almost because it seems to be working at a 100% success rate but time will tell if it misses a scrape here and there.
    Now my camera is bashing into the ball whenever the ball collides with vertical terrain at a high speed so I gotta find a work around for that, haha! Thank you so much for your help! :D
     
    HiddenMonk likes this.
  6. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Your camera goes towards the ball? Is your ball going through the walls for a frame? Use the frame play button to see if the ball interpenetrates the wall.
    Does putting the dontgothroughthings script from fixedupdate to lateupdate change anything?
     
    JanDawid likes this.
  7. JanDawid

    JanDawid

    Joined:
    Jul 7, 2014
    Posts:
    283
    Oh I was just in the midst of commenting that I fixed my camera bashing problem. What my camera does is that, to check for walls obstructing the view of the player, it goes in front of the object that is obstructing. What the DontGoThroughThings script does is that it corrects the ball's position after it has gone through, so my camera was zooming over to the ball for a frame and back out again. I just set the camera to not run its wall collision function if the DGTT script has to correct the ball's position for a frame. Problem solved. ^^

    I made my camera controller as part of a 'third person controller' asset that I've submitted to the asset store. It basically plays like a Zelda game, just waiting for approval. >.<
     
    devxigner and HiddenMonk like this.