- Home /
FixedJoint2D Setting the connected anchor to the point of contact between two objects.
Hi,
I am trying to make a 2D circle "Sticky" and using the FixedJoint2D component to do this. However when an object comes in contact with the collider on the Fixed joint sets the connected anchor to be the centerpoint of the object with the fixed joint component.
Is there anything that would allow me get the co-ordinates of the point of contact without having to do all the math?
Thank you in advance,
I'm very novice, but i achieved something similar by using this code:
joint.connectedAnchor = hit.point - new Vector2(hit.collider.transform.position.x, hit.collider.transform.position.y);
In my code "hit" was a raycast that I used to find the contact point - you will have to find a way to find to find your circles contact point (i'm thinking "Physics2D.OverlapCircle()"), then adjust the hitpoint away from the center of the object, which I've done after the assignment above. Again, I am very new to Unity. good luck.