Search Unity

How to prevent scroll from affecting rigidbody

Discussion in '2D' started by icanhazscreenid, Mar 10, 2020.

  1. icanhazscreenid

    icanhazscreenid

    Joined:
    Jun 2, 2016
    Posts:
    14
    I have a GameObject 2D circle with a rigidbody and a collider rolling down a hill (another object with an edge collider). Both objects are children of a scrollrect. All is well until the user scrolls. If the user scrolls down, the hill suddenly moves away away from the ball. So instead of rolling down the hill, the ball is free falling to the hill. My goal is to have scrolling not impact physics. So if the user scrolls, both objects scroll together (no physics required) with the ball still rolling down the hill. How is this accomplished? Is there a way to make physics only occur in a local space (not effected by the scroll parent)?
     
  2. icanhazscreenid

    icanhazscreenid

    Joined:
    Jun 2, 2016
    Posts:
    14
    Got it. I was moving the ball with velocity. Everything works as desired with AddForce.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Do not perform actions tha modify the Transform as you're undermining physics. Modifying the Transform is the primary reason to have a Rigidbody2D on your GameObject. Setting velocity directly doesn't break physics.