- Home /
Question was resolved.
Connecting SpringJoint2D to Rotating Rigidbody2D With Correct Anchor
I'm raycasting from my player object to a Rigidbody2D that can be rotated, and connecting a SpringJoint2D that connects the two with one anchor point on the point of impact, and the other on the player itself. This works perfectly when the Rigidbody2D isn't rotated, but the anchor point is incorrect when it is, since the rotation offsets it. It's important that the anchor point stays consistent to the hit point of the raycast even if the Rigidbody2D is rotated after the SpringJoint2D is connected. Here's a snippet of how I'm dealing with assigning the connected anchor right now:
if (hit)
{
grapplePoint = hit.point;
joint = gameObject.AddComponent<SpringJoint2D>();
joint.autoConfigureConnectedAnchor = false;
joint.connectedAnchor = grapplePoint;
joint.dampingRatio = damperConst;
joint.enableCollision = true;
joint.frequency = freqConst;
//Connected to rigidbody?
if(hit.transform.gameObject.GetComponent<Rigidbody2D>() != null)
{
connectedRb = hit.transform.gameObject.GetComponent<Rigidbody2D>();
joint.connectedBody = connectedRb;
joint.connectedAnchor = (new Vector3(hit.point.x, hit.point.y, 0f) - hit.transform.position);
}
}
Thank you in advance :)
Follow this Question
Related Questions
What can cause extreme velocity of 2D Rigidbodies? 0 Answers
basic questions about spring and joints in general 1 Answer
How do I set up a configurable joint to Behave like a Spring Joint? 1 Answer
How do I make a custom sliding joint? 0 Answers
How to get suspension or wheels collider with the new 2D unity tools 2 Answers