Transform joint.anchor to world coordinates

Hi,

I’m currently trying to create a joint anchor where raycast hit.point is touching. The problem is, hit.point is in world coordinates and joint.anchor is in local coordinates. How can I correct that ? I’m pretty sure I have to use transform.TransformPoint but I don’t know how.

Here’s my code :

ConfigurableJoint joint = longCube.AddComponent<ConfigurableJoint> ();
joint.anchor = hit.point;
joint.axis = hit.normal;

Thanks for reading.

transform.InverseTransformPoint(Vector3 position) converts position to the transforms local Space. In your case, position is the hit.point and transform should be the transform of longCube.

joint.anchor = longCube.transform.InverseTransformPoint(hit.point);