I have a simple axe-swing animation. I recorded moving the axe transform along with the hand of the character while in a swing animation. When I play the animation in the editor, it looks perfect:
cu4c3u
However, then when I enter play mode, the axe swing looks totally messed up. The axe is no longer on the hand. When I look in the inspector with the axe selected, its local position values are totally different from the ones I set.
gpz3gw
I’ve searched a while for an answer to this problem. I’ve set all keyframes to Both Tangents → Constant as was the solution for some people for a messed up animation.
Here is a recording of my animator as I am swinging the axe:
jg92pp
Here is the code that triggers the swing animation.
public class ItemUser : MonoBehaviour
{
// _itemParent is an empty game object that is the parent of the axe
[SerializeField] private GameObject _itemParent;
[SerializeField] private Animator _animator;
// Update is called once per frame
void Update()
{
// Check if character is mid-swing-animation
AnimatorClipInfo[] clipInfo;
clipInfo = _animator.GetCurrentAnimatorClipInfo(0);
if (clipInfo[0].clip.name != "skin_swing")
{
// If not in mid-swing, axe parent should be inactive
_itemParent.SetActive(false);
}
else
{
// If in mid-swing, axe parent should be active
_itemParent.SetActive(true);
}
// If mouse button is clicked, start swing animation
if (Input.GetMouseButtonDown(0))
{
_itemParent.SetActive(true);
_animator.SetTrigger("swing");
}
}
}
I’d really appreciate it if anyone has any ideas for what I could try to fix this. It’s totally stumped me!