Exactly, is the arms abrupt change what I want to avoid. In the reference video you can see how the leg is reoriented smoothly.
The code is pretty simple and I attached it in previous posts, but here you got the complete script (at least, what is related to the animation mixing):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
using Spine;
public class PlayerAnimationBehaviour : MonoBehaviour
{
[Header("General Animations")]
[SerializeField] [SpineAnimation] private string idleAnimation;
[SerializeField] [SpineAnimation] private string idleFace;
[SerializeField] [SpineAnimation] private string upAnimation;
[SerializeField] [SpineAnimation] private string downAnimation;
[SerializeField] [SpineAnimation] private string leftAnimation;
[SerializeField] [SpineAnimation] private string rightAnimation;
[SerializeField] private SkeletonAnimation skeletonAnimation;
public Spine.AnimationState spineAnimationState;
public Spine.Skeleton skeleton;
private TrackEntry up, down, left, right;
[Range(-1.0f, 1f)]
public float horizontal = 0f;
[Range(-1f, 1f)]
public float vertical = 0f;
[SerializeField] private bool isMovable = true;
void Awake()
{
spineAnimationState = skeletonAnimation.AnimationState;
skeleton = skeletonAnimation.Skeleton;
spineAnimationState.SetAnimation(0, idleAnimation, true);
spineAnimationState.SetAnimation(1, idleFace, true);
left = spineAnimationState.SetAnimation(2, leftAnimation, true);
right = spineAnimationState.SetAnimation(3, rightAnimation, true);
up = spineAnimationState.SetAnimation(4, upAnimation, true);
down = spineAnimationState.SetAnimation(5, downAnimation, true);
left.MixBlend = MixBlend.Add;
right.MixBlend = MixBlend.Add;
up.MixBlend = MixBlend.Add;
down.MixBlend = MixBlend.Add;
left.Alpha = 0;
right.Alpha = 0;
up.Alpha = 0;
down.Alpha = 0;
}
void Update()
{
if (isMovable)
{
BlendAnimations(moveInputs.x, moveInputs.y);
}
}
private void BlendAnimations(float horizontalInput, float verticalInput)
{
left.Alpha = (horizontalInput < 0) ? -horizontalInput : 0;
right.Alpha = (horizontalInput > 0) ? horizontalInput : 0;
up.Alpha = (verticalInput > 0) ? verticalInput : 0;
down.Alpha = (verticalInput < 0) ? -verticalInput : 0;
skeleton.SetBonesToSetupPose();
}
Let me know if this helps you clarify the issue or if I should approach this problem any other way.
Thank you!
Edit: moveInputs.x
and moveInputs.y
is provided by the RewiredManager, I did not include that part in the copied code.