Search Unity

Resolved Is there a method or something to 'connect' objects with another gameobject?

Discussion in 'Scripting' started by ArthurHaleta, Jun 11, 2022.

  1. ArthurHaleta

    ArthurHaleta

    Joined:
    Dec 24, 2021
    Posts:
    44
    thingthanf.png
    This is kind of what I mean; a string like object moves with two objects, and increases in width dynamically depending on the objects positions. I dont need the code, just to know if it exists and where to find it.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,856
    If we're talking a 2d line, in the Editor you'd use things like Gizmos.DrawLine, or Handles.DrawLine.

    In Runtime there's the Line Renderer component.
     
  3. ArthurHaleta

    ArthurHaleta

    Joined:
    Dec 24, 2021
    Posts:
    44
    And is it physically interactable?
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,856
    Oh, you mean like rope physics. There's a million and one tutorials out there for it. I believe it involves stuff like hinge joints.
     
    ArthurHaleta likes this.
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    You need to be clearer and more specific on what you mean if you want a useful answer. Physics or the visuals? Both?

    If you mean using 2D physics then yes, you can use the DistanceJoint2D to constrain two Rigidbody2D to be a certain distance apart with a configurable stiffness but that only applies if you want the joint to constrain two Rigidbody2D. It doesn't understand constraining arbitrary GameObject that you modify the position of via the Transform.

    As above, you can use the LineRenderer for visuals.

    I'd say you need to decide on what "moves" these GameObject. If it's you and not physics then physics won't be involved and you're then just talking about visuals via a LineRenderer.
     
    ArthurHaleta likes this.