Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sphere Collisions-sphere collider,rigidbody - physics engine

Discussion in 'Editor & General Support' started by ctsteve123, Aug 17, 2008.

  1. ctsteve123

    ctsteve123

    Joined:
    Sep 13, 2007
    Posts:
    51
    1) Made a sphere primitive that contains a sphere collider. Made a wood material

    2) Made another sphere primitive above this with a sphere collider and a rigidbody with gravity. Made a wood material.

    The problem is that the falling sphere , just stops when hitting the stationary sphere below it.

    Is there a way to simulate a real world collision between two wooden spheres?
     

    Attached Files:

  2. jeffcraighead

    jeffcraighead

    Joined:
    Nov 15, 2006
    Posts:
    740
    Both spheres need a rigidbody.
     
  3. ctsteve123

    ctsteve123

    Joined:
    Sep 13, 2007
    Posts:
    51
    I tried adding a rigidbody to the stationary sphere and then unchecking gravity. When the stationary sphere was hit though it started moving ( I didn't want the stationary sphere to move).

    I tried adding a constant force torque to the moving sphere and it does now behave properly. Is this the recommended way to simulate a real world collision?
     
  4. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Two points:

    - Your spheres are pretty big. This is why it appears to fall slowly.

    - Collisions are fine. If you want it to hit and roll off, just move it very slightly to one side.
     
  5. jeffcraighead

    jeffcraighead

    Joined:
    Nov 15, 2006
    Posts:
    740
    ah I didn't realize that the one sphere should remain fixed.
     
  6. ctsteve123

    ctsteve123

    Joined:
    Sep 13, 2007
    Posts:
    51
    Thanks for the responses. I was looking for a random collision on a fixed sphere. I was not clear in my posting.

    Here is my solution. I added this to the moving sphere.

    Code (csharp):
    1. function OnCollisionEnter() {
    2.     var changePos : Vector2 = Random.insideUnitCircle;
    3.    
    4.     rigidbody.AddForce( changePos.x , 0 , changePos.y );
    5.    
    6. }
     
  7. dock

    dock

    Joined:
    Jan 2, 2008
    Posts:
    603
    Could you mark the rigidbody as 'kinematic', or perhaps use a configurable hinge joint if that doesn't work. It shouldn't need code for this.
     
  8. ctsteve123

    ctsteve123

    Joined:
    Sep 13, 2007
    Posts:
    51
    Thanks for the suggestion. A hinge joint on the stationary ball, with anchor x,y set at .1 and axis x and z set at 1 allows for the moving ball to roll off to the right. I was looking for a random roll off when the moving ball hits the stationary ball. It would be nice not to use code and just the physics engine.