Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

2D - how to connect two separately rotating objects

Discussion in 'Physics' started by imaginaryhuman, Jan 20, 2021.

  1. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,705
    In 2d physics I need to do something like this ..... there are two shapes. The two shapes must always be at a specific fixed distance apart horizontally. Neither object rotates around the other. But, each object can rotate individually. The catch is, any physics collisions happening to one object, must be instantly translated to the other object, and vice versa. I imagine doing something like this:

    physics.jpg

    The two objects are permanently-joined at the 'center' with a fixed joint or a distance joint. There is no rotation allowed. They are to always be x width apart horizontally.

    The red line represent some other fixed joint, anchored away from the center. If either object collides with something, moves or rotates, it should instantly influence the other object. Any rotation around the center would cause the other object to be similarly rotated. And movement induced in one object pushes the other object.

    Would this work, with just the one anchored joint away from the center, or does that open up a possibility of the joint kind of collapsing where, when toward the right for example, the left shape might have its anchor position move down, while the right shapes anchor might move up? To counteract that would 2 or 3 such joints be needed?

    My main question though is, how do I structure this in unity? I presume I need 2 entirely separate game objects with rigid bodies? And then you link them together with the two (or more) joints? Is that all? Or does it need some fangled parenting thing? Do I need to add child objects within each in order to set up the anchor or can I just work with an x/y offset on the joint? What happens when it rotates, will that still work if the anchor has to rotate around the center of the object?
     
unityunity