- Home /
set the connected anchor of spring joint 2D
i'm ray casting from the player to the object with collider and rigidbody2D and i have hit.point, now i want to set my player springJoint2D's connected anchor to hit.point however hit.point is world space coordinate but connected anchor is locale-space coordinate from connected rigidbody i tried to subtract hit.point from connected rigidbody position but it set the position of connected anchor different from hit.point. any idea?
Answer by N-8-D-e-v · Sep 02, 2020 at 11:59 AM
I'm pretty sure you can just set autoConfigureConnectedAnchor to false, and the set the connected anchor to hit.point
yeah i did it but as i said connected anchor is locale-space coordinate from connected rigidbody but hit.point is world-space coordinate so the only problem here is how to convert hit.point to locale-space coordinate from connected rigidbody to spring joint 2D
Answer by axlxi1 · Sep 02, 2020 at 02:12 PM
OK i fixed it, it wasn't that complex that i think for those who may encounter this problem here's what i did : i created a empty GameObject and then reference it in my script and whenever i ray cast first set position of empty GameObject to hit.point and then set the parent of the empty GameObject to connected rigidbody now it's position is the that local space coordinate that i was looking for. im sure there a better approaches but it was the first thing that comes to my mind
Your answer