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

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,834
    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?