Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question I have a problem with collisions in my simple prototype when objects are fast moving

Discussion in 'Physics' started by pawelpoz, Jun 25, 2023.

  1. pawelpoz

    pawelpoz

    Joined:
    Dec 9, 2015
    Posts:
    2
    I have a problem with collisions in my prototype. I would like the balls, once they enter the box, not to fall out of the box when the box is moved fast. Unfortunately, when they enter and I move the box sideways, the balls pass through the box walls.

    I move the box using physics, specifically playerRb.AddForce(forceStrength * horizontalInput, 0f, 0f).

    My box consists of several objects:an Empty object (which has a Rigidbody component with Collision Detection set to Continuous Dynamic and a slightly smaller Box Collider, with the Is Trigger option enabled for counting the balls that enter the box), and 5 nested boxes that form the walls and floor of the box.

    These 5 boxes are Cube objects with Box Colliders and the Is Kinematic option enabled (to prevent the box from falling apart). The balls that enter the box are simply Sphere objects with Sphere Colliders and Rigidbodies set to Collision Detection Continuous Dynamic.

    I will provide the link to the WebGL build below. What am I doing wrong?

    WebGL: https://play.unity.com/mg/other/webgl-builds-355553

    Unity Package: https://drive.google.com/file/d/1iojATq69mFJmwYBa-mXmbmrXaMWQ_qjI/view
     
    Last edited: Jun 25, 2023
  2. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
    Your walls have rigidbodies? You only need one rigidbody (in the empty parent transform). Then in child transforms you put your cube objects with box colliders but no rigidbodies.
     
  3. malaron2

    malaron2

    Joined:
    Dec 18, 2023
    Posts:
    1
    I played around with your code. Not sure if this is the most efficient way however if you go into edit -> project settings -> time and change your Fixed Timestep to a lower number (Yours is at .02, I tried .005, there might be others that work). That fixed it for me using the code you provided.