• RuntimesUnity
  • About Physical Interaction

I want to implement a feature where when the player passes through grass, the grass gets pushed aside, and then returns to its original position after the player leaves.

I know I can do this using Unity's physics simulation, but can I achieve this using Spine's physics? Specifically, when the player collides with grass, can I apply a force to the Spine skeleton to drive Spine's physics simulation? Is this possible?

Related Discussions
...

To achieve the effect of grass being pushed aside when a player passes through it, you can use Spine's physics simulation in combination with Unity's physics system. While Spine's physics constraints can handle dependent movements within the skeleton, they do not directly support collision detection or force application from external objects like a player character. However, you can use Unity's physics system to detect collisions and then manipulate the Spine skeleton accordingly.

One approach is to use Unity's Rigidbody2D and Collider2D components to detect when the player collides with the grass. Upon collision, you can apply a force or adjust the position of the grass bones in the Spine skeleton to simulate the grass being pushed aside. You can use SkeletonUtilityBone to bridge between Unity's physics and Spine's skeleton, allowing you to manipulate the bones based on the collision events.

For example, you can set up a Rigidbody2D and Collider2D on the grass GameObject and detect collisions with the player. When a collision is detected, you can adjust the bones in the Spine skeleton to create the desired animation effect. After the player leaves, you can animate the bones back to their original position.

This approach leverages Unity's physics for collision detection and uses Spine's animation capabilities to create the visual effect of grass movement.

  • Harald вподобали це.

Nate
timeline ?

10 днів пізніше

Nate hi dude
finaly I use the unity physics simulation but I got the wrong result ( unity 2022.3 LTS & spine 4.2.40 )

I don't know what I'm looking at in the video, or what the right or wrong result would be. 😬

    Nate
    Sorry, I thought the difference was obvious so I didn't explain it. Now I will explain it.

    This is the spine skeleton before adding physics

    This is the result of adding Unity physics according to the official documentation.


    Look carefully, the shape of the leaves is different. I don't know if it's the mesh problem or the bone offset.(I observed that some meshes seemed to be mirrored.) I guess it's the bone offset, but I don't know why it's offset, because the hero in the document didn't deform after adding physics, but my mesh deformed.

      suanLoBeach I'm not sure if this has to do with the fact that I've set the scale of some of the slots in the spine to negative values, like (-6,5) (0.5,-0.6)

      Thanks! I think we'll need Harald to comment on this. Monday is a holiday but he'll be here Tuesday.

      @suanLoBeach Unfortunately it's impossible to tell from the video what exactly is going wrong. Also the video does not show whether you're in play mode or not, as it is cut below the play mode button, making it even harder.

      Please send us a minimal Unity project which still shows your issue (you can send it as a zip file or via a download link to contact@esotericsoftware.com as last time). Please also describe all necessary reproduction steps that we need to take to make the problem occur.

        Harald I have sent an Email to you ,
        Please let me know if you didn't receive it.

        @suanLoBeach Thanks for sending an email, we received it. Unfortunately I could not find any Unity project attached, nor any download link, just an mp4 file attached. Did I miss something, or did you perhaps forget to add the attachment?

          Harald oh, I fogot it, sorry, I'll send it right now

          • Misaki відповіли на це.

            suanLoBeach Thank you for sending us the Unity project that demonstrates your problem. We were able to open the Unity project without any problems and confirmed that the leaves have different appearances. However, what concerns us the most is the appearance of the skeleton when the scene is played. I attached a video showing the result to an email I sent you earlier. Can you confirm that this is the result you are looking for?

            The difference in the appearance of the leaves should be due to the bone rotations being overridden. However, if the result when you play the scene is different from what you want, I suggest you first create a state that achieves the correct result, and then ask us how to adjust the parts that are slightly different from your ideal.

            Also, in your first question you said that you wanted to implement grass that interacts with the player, so I wonder why you are creating a tree object that falls down by itself without any interference. As Spinebot initially indicated, if you want to create grass or trees that interact with the player, you will need colliders. What you should create is an object that moves according to the player's collision detection, and I suspect that you may not need to use SkeletonUtilityBone for your intended purpose.

            We hope you understand that we are confused because there seems to be a significant gap between what you say you want to achieve and what you are actually doing. From our perspective, Spinebot's initial answer was quite accurate. If you tried it and there was something you were unsure about, we would be happy to help you with those questions, but if you start from a completely different place, it becomes difficult to understand what you are trying to achieve.

              Misaki Hi there

              The final effect I want to achieve is having tree branches sway in the wind. This example scene is only meant to demonstrate the 'deformation' error I'm encountering; it doesn't represent my final goal. For the final implementation, I only need to enable physics simulation for a small number of branches. You can actually reproduce the error in this scene as well by enabling Unity physics just for the bones that have leaves attached.

              You might suggest using animation, but I have a very large number of plants, and creating animations for all of them would add too much to the cost. That's why I opted for physics simulation, so the movable parts can react uniformly to the wind in the scene.

              My current question is: why am I getting this deformation error, and how can I fix it? I ask because I observed that when the 'hero' example from the official documentation is processed similarly, its cape doesn't deform, whereas my tree does.

              I see you mentioned that the bone rotations are being overridden, but why aren't the rotations of the hero's bones in the documentation overridden? Do you need my Spine project?

              Misaki

              Misaki I saw the replies from Nate and spineboy earlier. Perhaps I'll try using scripts to control the skeleton's 'wind' value to simulate the wind effect. Are there any example scenes or tutorials available for controlling Spine physics via script? I've searched the official website and the runtimes but haven't found anything.

              @suanLoBeach The problem with your reproduction project is that Create 2D Hinge Chain supported only pure chains with a single child bone downwards, no branching into multiple tree banch sub-chains.

              This has just been improved (fixed) on the 4.2 branch, for both Create 3D Hinge Chain and Create 2D Hinge Chain. A new spine-unity 4.2 unitypackage is available for download:
              https://esotericsoftware.com/spine-unity-download
              Please note that we still do not recommend using Unity's physics components at a tree for wind animation.

              Issue ticket URL for later reference:
              EsotericSoftware/spine-runtimes2825

                Harald Thank you for your work. I am using the code provided by Ms. Misaki to create my wind control script. I've already made good progress with it. For now, I've decided to abandon using Unity's built-in physics for creating dynamic environments.