diff --git a/unity/Runtime/Components/Equality/MjConnect.cs b/unity/Runtime/Components/Equality/MjConnect.cs index efdb93a1..23343089 100644 --- a/unity/Runtime/Components/Equality/MjConnect.cs +++ b/unity/Runtime/Components/Equality/MjConnect.cs @@ -22,14 +22,17 @@ namespace Mujoco { public class MjConnect : MjBaseConstraint { public MjBaseBody Body1; public MjBaseBody Body2; + public Transform Anchor; protected override string _constraintName => "connect"; protected override void FromMjcf(XmlElement mjcf) { Body1 = mjcf.GetObjectReferenceAttribute("body1"); Body2 = mjcf.GetObjectReferenceAttribute("body2"); - if (mjcf.GetStringAttribute("anchor") != null) { - Debug.Log($"anchor in connect {name} ignored. Set Transforms in the editor."); - } + var anchorPos = MjEngineTool.UnityVector3( + mjcf.GetVector3Attribute("anchor", defaultValue: Vector3.zero)); + Anchor = new GameObject("connect_anchor").transform; + Anchor.parent = Body1.transform; + Anchor.localPosition = anchorPos; } // Generate implementation specific XML element. @@ -39,6 +42,8 @@ namespace Mujoco { } mjcf.SetAttribute("body1", Body1.MujocoName); mjcf.SetAttribute("body2", Body2.MujocoName); + mjcf.SetAttribute("anchor", + MjEngineTool.Vector3ToMjcf(MjEngineTool.MjVector3(Anchor.localPosition))); } public void OnValidate() {