• RuntimesUnity
  • How can I make some leaf animations like in Ori

[

not the flying leaf, i mean the animations of the part of green leaf

these green leaf look like very elasticity.
is it made by mesh in spine ? or shader in Unity ?

To create leaf animations similar to those in Ori, you can use a combination of techniques in Spine and Unity. In Spine, you can use mesh deformation to create the elasticity effect by manipulating the vertices of the leaf mesh. This allows you to animate the leaf bending and swaying as if affected by wind. Additionally, in Unity, you can enhance this effect using shaders. A shader can simulate the movement of leaves by applying sine-wave motion or other vertex displacement techniques, which can give the appearance of elasticity and natural movement. This approach is similar to how grass or foliage shaders work, where the movement is based on the distance from a fixed point, creating a dynamic and convincing animation.

    Spinebot should I use mesh in spine or use directly unity shader to achive vertex displacement ? I need the leaf is interactive with player

    • Misaki ha risposto a questo messaggio

      suanLoBeach I initially thought your goal could be easily achieved with physics constraints and bone followers, so I considered recommending existing examples. However, realizing there might not be a direct reference, I created a simple example instead.

      First, I made a flower using physics constraints, where its swaying motion is animated by rotating the bones. Additionally, I created an animation that integrates IK constraints in Unity, similar to the aim animation in Spineboy:

      The Spine project file can be downloaded here:

      flower.zip
      54kB

      Next, I used Bone Follower to make a Box Collider 2D follow the bones around the middle of the flower (flower_3). When the mouse enters the Collider's range, the IK animation is applied on track 1, causing the IK target bone to follow the mouse position. This interaction inhibits the flower’s movement when the mouse hovers over it. Once the mouse exits the Collider’s range, the animation on track 1 mixes out, and the IK bones return to their original position. (For the animation on track 0, the IK target bone is constrained by a transform constraint to match the position of the flower_2 bone, ensuring they return to their original position.)

      InteractingWithFlowe.cs:

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using Spine;
      using Spine.Unity;
      
      public class InteractingWithFlower : MonoBehaviour
      {
          public SkeletonAnimation skeletonAnimation;
          public Spine.AnimationState spineAnimationState;
      
          [SpineBone(dataField: "skeletonAnimation")]
          public string boneName;
          public Camera cam;
      
          Bone bone;
      
          void OnValidate () {
              if (skeletonAnimation == null) skeletonAnimation = GetComponent<SkeletonAnimation>();
          }
      
          void Start () {
              spineAnimationState = skeletonAnimation.AnimationState;
              spineAnimationState.SetAnimation(0, "animation", true);
      
              bone = skeletonAnimation.Skeleton.FindBone(boneName);
          }
      
          void OnMouseOver () {
      	Debug.Log("OnMouseOver");
              if(spineAnimationState.GetCurrent(1) == null){
                  spineAnimationState.SetAnimation(1, "IK", false);
              }
              Vector3 mousePosition = Input.mousePosition;
      	Vector3 worldMousePosition = cam.ScreenToWorldPoint(mousePosition);
      	Vector3 skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
      	skeletonSpacePoint.x *= skeletonAnimation.Skeleton.ScaleX;
      	skeletonSpacePoint.y *= skeletonAnimation.Skeleton.ScaleY;
      	bone.SetLocalPosition(skeletonSpacePoint);
              skeletonAnimation.Skeleton.UpdateWorldTransform(Skeleton.Physics.Update);
          }
      
          void OnMouseExit() {
              Debug.Log("OnMouseExit");
              spineAnimationState.SetEmptyAnimation(1,0);
          }
      }

      I’ve written a lot, but there are many different approaches to achieving the same result. For example, in this case, I enabled the IK constraint by playing an animation on an upper track. However, since the IK Mix value can be changed directly via script, that approach could work as well.

      I’m not sure if my method is the best fit for what you want to achieve, but I hope it helps you get a better idea of what can be done with Spine and the spine-unity runtime.

        Misaki
        thanks lady
        it's a good idea. You inspired me, I can use physics to achive inertia affect instead of shader like vertex displacement.