Set the Break Point of a SpringJoint2D

Hi everyone!

I have a simple mockup game with some draggable ghosts (sprites). Sometimes the sprites will be stuck in the level obstacles, and i need the springJoint2D to “break” when the distance between the Sprite and the Cursor are too long. Like a “MaxDistance” value.

The SpringJoint is place via script, and I can’t figure out how to listen neither the _SpringJoint2d.anchor or _SpringJoint.connectedAnchor positions.

alt text like this.

I am using something like:

if ("Distance between" > MaxDistance) {
StopCoroutine ("DragObject");
};

But i dont know how to describe this “Distance between”…

Someone have a solution for this?

A vector minus a vector gives the length between those two vectors… The magnitude is the distance… But you want to use square magnitude.

/**** PSEUDOCODE ***/
distanceSquared = (itemPosition - jointPosition).sqrMagnitude;

if(Mathf.Pow(distanceThreshold, 2) < distanceSquared){
//do logic.
}