DistanceJointComponent

You can create and delete DistanceJoint. Keeps the distance between connected rigid bodies constant.

# Properties

[{"index":"SyncList Joints (Sync) (ReadOnly)","0":"Set Joint information."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

[{"index":"int32 AddJoint(Entity targetEntity, Vector2 localAnchorA, Vector2 localAnchorB, float length)","0":"Add DistanceJoint. Return index on success, -1 on failure"}]

[{"index":"void DestroyJoint(int32 index)","0":"Removes the Joint whose sequence number corresponds to the index."}]

[{"index":"int32 GetJointsCount()","0":"Return the number of joints."}]

[{"index":"void SetCollideConnected(int32 index, boolean collideConnected)","0":"Set the CollideConnected value of the Joint whose sequence number corresponds to index."}]

[{"index":"void SetLength(int32 index, float length)","0":"Set the Length value of the Joint whose sequence number corresponds to index."}]

[{"index":"void SetLocalAnchorA(int32 index, Vector2 localAnchorA)","0":"Set the LocalAnchorA value of the Joint whose sequence number corresponds to index."}]

[{"index":"void SetLocalAnchorB(int32 index, Vector2 localAnchorB)","0":"Set the LocalAnchorB value of the Joint whose sequence number corresponds to index."}]

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Examples

#### AddJoint

This is an example of pressing R, adding Joint, and catching the falling ball.
    
    
    @Component
    script BallTetherToggle extends Component
        @ExecSpace("ServerOnly")
        method void Connect()
        local ball = _EntityService:GetEntityByPath("/maps/map01/Ball")
    
        self.Entity.DistanceJointComponent:AddJoint(
        	ball,
        	Vector2.zero,
        	Vector2.zero,
        	Vector2.Distance(ball.TransformComponent.WorldPosition:ToVector2(), self.Entity.TransformComponent.WorldPosition:ToVector2())
        	)
    
        self.Entity.LineRendererComponent.Enable = true
        end
    
        @ExecSpace("ServerOnly")
        method void Disconnect()
        self.Entity.DistanceJointComponent.Joints:Clear()
    
        self.Entity.LineRendererComponent.Enable = false
        end
    
        @EventSender("Self")
        handler HandleKeyDownEvent(KeyDownEvent event)
        --------------- Native Event Sender Info ----------------
        -- Sender: InputService
        -- Space: Client
        ---------------------------------------------------------
    
        -- Parameters
        local key = event.key
        ---------------------------------------------------------
        if key == KeyboardKey.R then
        	if self.Entity.DistanceJointComponent:GetJointsCount() == 0 then
        		self:Connect()
        	else
        		self:Disconnect()
        	end
        end
        end
    end
    

# SeeAlso

  * LineRendererComponent
  * TransformComponent
  * KeyDownEvent
  * EntityService
  * InputService
  * [Applying Physics to Entities ](/docs?postId=761)
  * [Using Physics](/docs?postId=757)
  * [Using Various Physics Joints](/docs?postId=760)