From 66a0cd3b0b5249ceb0b0d89aa1994ff39cd11e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Hodossy?= Date: Thu, 11 Jan 2024 16:29:08 +0000 Subject: [PATCH] Perform autolimit check on actuators --- unity/Runtime/Components/MjActuator.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/unity/Runtime/Components/MjActuator.cs b/unity/Runtime/Components/MjActuator.cs index 4bdffe87..a72ba30c 100644 --- a/unity/Runtime/Components/MjActuator.cs +++ b/unity/Runtime/Components/MjActuator.cs @@ -77,12 +77,17 @@ public class MjActuator : MjComponent { } public void FromMjcf(XmlElement mjcf) { - CtrlLimited = mjcf.GetBoolAttribute("ctrllimited", defaultValue: false); - ForceLimited = mjcf.GetBoolAttribute("forcelimited", defaultValue: false); CtrlRange = mjcf.GetVector2Attribute("ctrlrange", defaultValue: Vector2.zero); ForceRange = mjcf.GetVector2Attribute("forcerange", defaultValue: Vector2.zero); LengthRange = mjcf.GetVector2Attribute("lengthrange", defaultValue: Vector2.zero); Gear = mjcf.GetFloatArrayAttribute("gear", defaultValue: new float[] { 1.0f }).ToList(); + + bool autolimits = mjcf.OwnerDocument.GetElementsByTagName("compiler")[0] is not XmlElement + compilerElement || compilerElement.GetBoolAttribute("autolimits", true); + CtrlLimited = mjcf.GetBoolAttribute("ctrllimited", + defaultValue: autolimits ? CtrlRange != Vector2.zero : false); + ForceLimited = mjcf.GetBoolAttribute("forcelimited", + defaultValue: autolimits ? ForceRange != Vector2.zero : false); } }