Search Unity

A stationary ball staying still even after object below it moves...

Discussion in 'Getting Started' started by Tset_Tsyung, Jan 24, 2016.

  1. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Hey all,

    Still a total noob to Unity (sorry :s ) but I have a new bug, which is an interesting one.

    I'm using a mesh (hacked together in Blender) to simulate a wooden board with holes in it. The player controls the rotation of the board to guide a marble/ball bearing/sphere to the winning hole at the end. However, when the game starts and the ball drops, if the board is still (and therefore the ball goes still on a level plane) the ball will 'stick' there when you try to rotate the board.

    For example. If you tilt the board backwards (the ball is in the bottom left corner causing the ball to no longer touch the board) it can take up to 2 seconds for the ball/physics engine to 'realise' that it should be dropping.

    And with the revers (tilting board forwards) the ball goes THROUGH the board mesh and, if you rotate the board PAST the ball, it will again realise some seconds later and drop into the void below.

    I've done a search on the net, read some similar problems (learnt I have my scale WAAAYYYY too large, but nvm) and I can't seem to find what I've done wrong, lol. Any ideas what I'm missing?
     
  2. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    1. did you fix the scale issue in blender for both ball and board?
    2. if I read this correctly, then the ball has a sphere collider+rigidbody, and the board has a mesh collider yes?
    3. what are the values for the rigidbody component? (mass etc.)
     
    Tset_Tsyung likes this.
  3. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Hi @Farelle,

    Thanks for the reply.

    1. If by scale issue you mean "APPLY" the scale in blender before importing, yes done that (if that was you who told me to do that in my previous post, thanks again ;) )

    2. Correct assumption, however the 'walls' of the board are done by box colliders (only the floor is a mesh collider to cater for the circular holes).

    3. Ball:
    Mass 1-3 (tried this at different values, always same outcome)
    drag and angular drag are 0.
    Gravity is checked.
    Kinematic is off
    Interpolate is set to Interpolate (understanding is that this is better for 'character' pieces)
    Collision is either Continuous or Continuous Dynamic (always same outcome.

    Just want to reiterate. The player controls the board directly, but the ball is the main 'moving' item. Don't know if that helps... but wanted to say it anyway.

    P.S. Will reply in morning, been busy day :s lol
     
  4. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    so i made a testscene and apparently there is indeed a problem with collision detection, not sure if this is a bug, but it works fine if I Immediately after starting the scene (when the ball is still dropping from initial height) move the board.
    But if I wait until it stands still, the collision is lacking behind, sometimes not reacting on repeated try to collider with a simple cube collider....
    soooo....based on that I made a little patch aid, which is simply adding an additional force to the ball over time, so that even if it appears to be standing still is always getting Updated, no matter if gravity of rigidbody is registering loss of ground underneath or not:


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class BallCollision : MonoBehaviour {
    6.    
    7.     public Rigidbody rb;
    8.  
    9.     void OnCollisionEnter(Collision col)
    10.     {
    11.         Debug.Log("Collision");
    12.     }
    13.     // Use this for initialization
    14.     void Start () {
    15.         rb = GetComponent<Rigidbody>();
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void FixedUpdate () {
    20.  
    21.         rb.AddForce(-transform.up * Time.deltaTime);
    22.    
    23.     }
    24. }
    25.  
    Put this code on the ball :)
    I hope this helps.
     
    MikeTeavee likes this.
  5. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Thank you Farelle,

    See, I was thinking something like a basic downward force, but was worried that it wouldn't work if you tilted forward (which would usally push the ball through the mesh) and also wasn't sure exactly how to go about it. My main concern was that if this problem was from something I was doing wrong with the code or engine that I would cause more problems down the line for myself in this project AND through bad coding habits.

    However, once again your advice has been excellent and simple. Many thanks Farelle - you're an absolute legend.

    I'm really starting to think that I'm giving up too easily with these problems, lol. I'll try to hold out longer next time ;)
     
  6. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    no problem :) and don't worry too much about asking too many questions :D you will get to the point early enough that no one knows how to help you and you would need to figure it out yourself :p

    But besides that, I also had to learn that just trying out things that you think might work, is the best way to go. Always deal with problems the moment they arrive. Of course with experience, you can avoid some problems upfront, but as long as there is no experience it's just a never ending loop of not knowing what possible problems could arise :) aka it usually ends in not doing anything out of fear that one could stumble on a problem one can not foresee *rollseyes*

    edit: maybe should file a bug report though, because I think what I did with adding a little force on it, should be actually happening all the time through the gravity property....I'm not sure why it seems to be off sometimes....and it's not random either. Which is why i think it's possible that unity intends in general rigidbodies to be moved directly and not just being moved by colliders.
     
    Last edited: Jan 25, 2016
    Tset_Tsyung likes this.
  7. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Yeah, I think I'll have a look, perhaps it's a known issue already, if not I'll post it.

    Thanks again Farelle ;)