• RuntimesUnity
  • Can i rotate an animation in Unity using C#?

Hello. Can i rotate an animation in Unity using C#? We can do this skeleton.ScaleX = -1; , but can i do the same for rotation?

Related Discussions
...

Skeleton has a position and scale but doesn't have a rotation. You can rotate the root bone. If you animate the root bone, you'll need to reapply your rotation every frame.

Another option is to rotate the GameObject instead of the skeleton.

    Nate Ok, i'll explain my problem - i have a model with 2 animations(walk, attack) and attack animation is fireball casting, fireball fly and explode. I need to change the direction of fireball fly and its distance. How cat i do it? May be i need 3 different animations(cast, fly, explosion) to do it? Or can i change bone rotation to resolve this problem?

      sxweb You can override a specific bone's position, rotation, scale using the SkeletonUtilityBone component. Please refer to the spine-unity runtime documentation for more information:
      http://esotericsoftware.com/spine-unity#SkeletonUtilityBone

      May be i need 3 different animations(cast, fly, explosion) to do it?

      No, that would not be necessary. I think it is possible to add an event key at the time you want to start overriding the bone's position and rotation and have it trigger the override without having to split the animation into three separate animations. If you are not familiar with event keys, please see the Events page of the Spine User Guide: http://esotericsoftware.com/spine-events

      Also the Processing AnimationState Events section of the spine-unity runtime documentation would be helpful.

        Misaki thanks a lot! I resolve it using bone.Rotation. But i cant understand how to change animation distance. For example = i have an attack animation and target for attack but animation disatnce is to short, how can i change an animation length?

          sxweb I'm afraid I'm not really sure what "animation distance" is. Since you mentioned that it is an animation attacking with a fireball, I thought you could just adjust the position of the fireball bone by overriding it, is that not what you are looking for?
          What do you need to do to reach the target of the attack? (Does the character's position have to move, only certain bones have to move, or are there other conditions?)

            sxweb Thank you for sharing the image. It seems to me that you can still achieve your goal by overriding the position of the fireball's bone and moving it to reach the target. Or, if you create a path for the fireball's track, and use the Position property of the path constraint to make the fireball move along that track, and bind that path to a bone so that the path can be stretched and squashed when that bone is moved, then you can move the position of the bone in Unity to match the target.
            If this explanation is not clear, feel free to ask additional questions.

              Misaki Ok, thanks a lot. I'll try to set position for fireball bone.

              I would have a fireball skeleton and animate the fireball and explosion (in a single animation or multiple) without animating the movement. At runtime, move the fireball GameObject from the character to the target. You can make the movement more interesting by making it an arc. Adjust the fireball root bone rotation so it points in the direction it is moving.

              @"Nate"#p109218The fact is that I have a complex animation structure, with a cast effect(https://disk.yandex.ru/i/pJ0OrwGhVVnQAQ) at the beginning, a fireball flight(https://disk.yandex.ru/i/h-l132cJvqzF_A) and an explosion(https://disk.yandex.ru/i/F97th1yAVajq3Q). Perhaps you need to somehow move the bone of the ball's flight after the cast animation has passed, but for this you need some triggers in the animation, I do not know if they can be installed in unity on a ready-made animation. I have 4 diferent bones and i dont know how to check what does each of them affect https://disk.yandex.ru/i/6HT61KYtLPfxqA . Maybe I can move a fireball using one of these bones.

              sxweb Looking at the Hierarchy window, it appears that GameObjects which reflect the bone hierarchy are not being generated. Could you try adding the component again following the instructions in the SkeletonUtility component section?: http://esotericsoftware.com/spine-unity#SkeletonUtility
              I mean please delete the added SkeletonUtilityBone component that you have already added, and try adding SkeletonUtility component by hitting the Add Skeleton Utility button in the Advanced section of the SkeletonAnimation component, hit the Spawn Hierarchy button on the added SkeletonUtility component, then add the SkeletonUtilityBone component.

              How to set a bone's transform without using the SkeletonUtilityBone component is described in the "Getting and Setting Bone Transforms Manually" section of the documentation:
              http://esotericsoftware.com/spine-unity#Getting-and-Setting-Bone-Transforms-Manually
              However, as noted in that section, using SkeletonUtilityBone is the easier and recommended way.

              4 天 后

              @sxweb Please note that having a fireball share the same skeleton with the caster comes with some drawbacks: when you want to cast two fireballs in succession before the first one has disappeared, you run into problems. Personally I would split the fireball from the caster (or any projectile from its spawning device) as soon as it is detached logically from it, i.e. as soon as it should not move along with the caster any more.

              It depends on your intended use-case of course, just wanted to mention that to save you some potential troubles down the road.