• RuntimesUnity
  • Physics Related Question : Separate Gameobject transform from Skeleton bones ?

Hi !
I have a question about the physics in Unity.
I've seen you've added two bool for the physics, and that's cool, to deactivate / activate the physics.

I have a scene with a canvas, so UI, with Skeleton Graphic. I created a script to zoom and move it, something really simple that just scale and move a parent gameoject of the skeleton.
The problem is that it affect the physics when it move.
For now I'm using this simple function before zooming / moving and after :

        public void Physics(bool value)
        {
            skeleton.applyRotationToPhysics = value;
            skeleton.applyTranslationToPhysics = value;
            skeleton.ResetLastPositionAndRotation();
        }

And it is working pretty great, as it is moving or zooming at the same time, we don't see that the physics is disabled temporary.
So I was just wondering if it was planned to can separate physics between skeleton and gameobject.

Anyways, as always, nice job 👏​ Can't wait for the beta 4.2.10 though !

  • Harald がこの投稿に返信しました。
    Related Discussions
    ...

    Pentacles So I was just wondering if it was planned to can separate physics between skeleton and gameobject.

    I'm not sure what exactly you mean by "separate physics between skeleton and gameobject", could you describe in more detail what you would like to achieve?

    In general the effect on PhysicsConstraints of the GameObject Transform is already separated from the skeleton's internal bone movement. If you set SkeletonAnimation.applyTranslationToPhysics = false, only internal Skeleton bone movement will have any effect, GameObject translation will be ignored.
    (Your code reading skeleton.applyRotationToPhysics = value; is a bit misleading above, as it's referring to a SkeletonAnimation component and not SkeletonAnimation.skeleton)

    I assume that you want to only apply local Transform movement of your GameObject in relation to its parent, and not the world movement of the GameObject, is that correct? In general its a good idea to have the movement-parent configurable, thanks for the input! We will consider the best way to support this and later provide an update with this feature.

      Harald I assume that you want to only apply local Transform movement of your GameObject in relation to its parent, and not the world movement of the GameObject, is that correct? In general its a good idea to have the movement-parent configurable, thanks for the input! We will consider the best way to support this and later provide an update with this feature.

      @Pentacles We have just added the feature to specify a Transform for relative movement to be used for PhysicsConstraints instead of world-space movement.

      From the changelog:

      • PhysicsConstraints: Skeleton components now allow you to use relative instead of world-space Transform movement (with applyTranslationToPhysics and applyRotationToPhysics) by assigning a Transform (typically the parent) to the new Movement relative to property. Leave this property at null (the default) to use world-space Transform movement for physics.

      A new spine-unity 4.2-beta unitypackage is available for download here as usual:
      https://esotericsoftware.com/spine-unity-download
      Thanks again for your input!

      Harald
      By separated physics between skeleton and gameobject, I was talking indeed about world space and local space position. Like moving the parent gameobject or the direct spine gameobject.
      Sorry that I wasn't more precise

      The funny thing is... I made a really stupid mistake... I tried unchecking it in the editor during play mode.
      So, yes, it deactivated everything... If I had unchecked it BEFORE launching the game to see, everything would have worked as it's supposed to and I wouldn't even had the bother to make a script for something that was actually already here to begin with.
      So I just jumped on the moving train without even looking back 🥲
      And for the code, I accessed this function via the SkeletonGraphic, and not the SkeletonAnimation.
      [SerializeField] private SkeletonGraphic skeleton;
      Okay so I can go hide in shame forever now I guess

      That said, having the option to choose between worldspace and localspace is great.
      You're really fast 👍 Good job
      I'll update the unitypackage right away

      • Nate が「いいね」しました。

      @Pentacles No need to apologize. Thanks for sharing your experience and problems, it's always good to hear where things can go wrong or can be misunderstood. It can then either help other users avoid the same issue, or we can perhaps prevent the issue from happening in the first place.

      All in all it helped us cover a pretty common use case early on, so thanks again for your input! 🙂

      And for the code, I accessed this function via the SkeletonGraphic, and not the SkeletonAnimation.
      [SerializeField] private SkeletonGraphic skeleton;

      Ok, that's basically similar, I just meant that skeleton references SkeletonGraphic and not SkeletonGraphic.Skeleton.

      • Pentacles がこの投稿に返信しました。

        Harald
        Something that could be usefull too is a "strengh modifier" on the physics, gameobject movement related.
        For me it's usefull because I wanted to add a little physics on the scrollview for choosing the character, but it can be usefull for more common things, like level with a lot of gravity and one with zero gravity or so.

        It's just an idea though... I'm gonna see if I can implement it myself easilly or not 🤔

        • Pentacles がこの投稿に返信しました。

          Pentacles
          For the "strenghtener" it was pretty simple, a simple float to multiply here :
          skeleton.PhysicsTranslate(positionDelta.x * physicsStrenghtener, positionDelta.y * physicsStrenghtener);
          The most difficult was to actually add it to your awersome Editor script 🫡

          Something nice would be a limiter to ensure it doesn't go outside a certain point, but I'm not sure if this is doable at the moment ... Gonna check it too !

          Your scripts are all well documented 👍

          @Pentacles A strength modifier is a cool idea, thanks for your input! Basically all that needs to be done is to multiply the translation or rotation delta with a multiplier parameter that defaults to 1.0. I will give it some more thought and potentially test and add that feature next week.

          @Pentacles Sorry, I should have refreshed the browser tab before posting, you already implemented it 🙂. Glad to hear it was easy to add for you, thanks for your kind words! 🙂

          • Pentacles がこの投稿に返信しました。

            Harald
            No problem, the modifier was pretty easy, but the limiter doesn't work great 😅

            I tried a clamp at the same location but then it start looking like it's lagging when slowing down...
            I suppose it would be more on the "PhysicsConstraint" class, but as it is not yet implemented in spine itself I don't think I can do it in Unity, right ? (If I remember right, there was a post to make a limiter on the physics in Spine)

            But I think being able to modify the strengh is always pretty nice 🙂 It gonna need a "physics" dropdown soon 🤣

            • Harald がこの投稿に返信しました。

              Pentacles No problem, the modifier was pretty easy, but the limiter doesn't work great 😅
              ..
              Pentacles I suppose it would be more on the "PhysicsConstraint" class, but as it is not yet implemented in spine itself I don't think I can do it in Unity, right ?

              Yes, we are planning to add a limiter on the Spine side of things (configured in the Spine Editor). Adding limiters outside of a skeleton (e.g. in the SkeletonAnimation component) will never be suitable for all scenarios unfortunately. It might take some time until we get to release this feature though, so it might still be a good idea if you use your solution in the meantime.

              Pentacles It gonna need a "physics" dropdown soon

              What kind of dropdown do you mean, what do you have in mind?

              • Pentacles がこの投稿に返信しました。

                Harald
                Well, for now I will use only the physics strengtener modifier. I am already hyped for the beta 4.2.10 (constraint folder... and repaired import... What to ask more ?) , but being able to limit it between value will be really great too !

                For the dropdown, it was more a joke than something serious, it's because there's a lot of stuff now for the physics.
                But I was thinking the same as the dropdown for "advanced" in the skeleton gameobject, where you have for now all the physics, multipleCanvasRenderer, those stuff.
                I don't know if dropdown is the right word though.

                Ah, you mean "foldout", that makes sense then, thanks for the clarification 🙂.

                • 編集済み

                @Pentacles FYI: We have just pushed a commit to the 4.2-beta branch which replaces the ApplyTranslationToPhysics and ApplyRotationToPhysics bool properties (and their Inspector counterparts Transform Translation and Transform Rotation) with Vector2 and float scale-factor properties. This covers disabling the feature by setting the factors to 0.

                A new spine-unity 4.2-beta unitypackage is available for download as well:
                https://esotericsoftware.com/spine-unity-download#spine-unity-4.2-beta

                From the changelog:

                PhysicsConstraints: bool properties ApplyTranslationToPhysics and ApplyRotationToPhysics were changed to Vector2 PhysicsPositionInheritanceFactor and float PhysicsRotationInheritanceFactor to allow the Transform movement the be scaled by a factor before being applied to the skeleton. You can set the properties to Vector2.zero and 0 respectively to disable applying any Transform movement at all. The Advanced Inspector section Physics Constraints was renamed to Physics Inheritance, the properties in the section are now called Position and Rotation.

                PhysicsConstraints: Skeleton GameObjects now automatically apply Transform translation and rotation to the skeleton's PhysicsConstraints. You can disable applying translation or rotation at the Skeleton component Inspector under Advanced - Physics Inheritance by setting Position to (0,0)and Rotation to 0, or by setting the properties physicsPositionInheritanceFactor to Vector2.zero and physicsRotationInheritanceFactor to 0 at the skeleton component via code.

                I would recommend you to back up your current project and update early if possible, since the property changes are breaking changes. In other words, you need to re-configure any of your custom Transform Physics Inheritance settings (either disabled or using a strength modifier other than 1), since the old bool parameter no longer exists and your own parameter is likely named differently. And it's better to do it early than late where you might then need to re-do more configuration work.

                If you want to migrate your own strength modifier parameter, you can add
                [UnityEngine.Serialization.FormerlySerializedAs("yourTranslationModifierVariableName")]
                before the line
                [SerializeField] protected Vector2 physicsPositionInheritanceFactor = Vector2.one;
                in SkeletonRenderer.cs and the same for physicsRotationInheritanceFactor before opening your scenes (or before opening Unity at all). Then you should not loose any of your settings.

                @Jamez0r Pinging you here as well just in case you've already updated to the previous package, so that you can avoid losing any settings as well.

                The documentation page will be updated accordingly very soon as well.
                Hope you like it 🙂.

                  Harald
                  Thanks for the tips of "UnityEngine.Serialization.FormerlySerializedAs", I didn't knew that !
                  Well I'm probably gonna do this then.
                  Nice idea to split it between position and rotation too !
                  I'm gonna change it tomorow, I'm using it on two scenes only so it won't take long hopefully 🙂 I was waiting your official push 😉

                  • Harald がこの投稿に返信しました。

                    Harald Ooo, good idea with the scale value 👍️ and thanks for the heads up!

                    • Harald がこの投稿に返信しました。
                    • Harald が「いいね」しました。

                      Pentacles Thanks for the tips of "UnityEngine.Serialization.FormerlySerializedAs", I didn't knew that !
                      Well I'm probably gonna do this then.

                      Glad it helped!

                      Pentacles Nice idea to split it between position and rotation too !

                      And you can also easily split it between horizontal and vertical movement as well, just set the Position vector to e.g. (1, 0) to only get horizontal movement, or (2, 1) to get normal vertical but twice as intense horizontal movement. 🙂

                      Jamez0r Ooo, good idea with the scale value 👍️ and thanks for the heads up!

                      It was @Pentacles idea, so I hereby redirect the praise 🙂.

                      @Pentacles FYI: We've also just added configurable default values for the Physics Inheritance Position and Rotation scale factor properties to Spine Preferences:
                      https://esotericsoftware.com/spine-unity#Spine-Preferences
                      This should save a lot of work when you e.g. want to e.g. set your Rotation scale factor to 0 (disabled) at all skeletons by default.

                      Also, the spine-unity documentation page has been updated to reflect the updated physics Inspector properties.

                      A new spine-unity 4.2-beta unitypackage is available for download:
                      https://esotericsoftware.com/spine-unity-download#spine-unity-4.2-beta