Search Unity

Sword swing animation problems

Discussion in 'Animation' started by McC1oud, Mar 7, 2019.

  1. McC1oud

    McC1oud

    Joined:
    Mar 14, 2015
    Posts:
    96
    Hi there, I created a basic animation with a sword that swings designed for a first person camera. I'm not entirely sure how to setup the sword relative to the camera position in Unity, so I just decided I'll animate it from it's zero'd out position and run a few tests to see how the animation lines up. Good news is I fluked the animation and exported it to Unity and positioned and rotated it in front of the first person as you would to hold a sword. Besides tweaking the animation itself to have some better follow through on the swing, the setup seemed quite nice.

    The big issue was that out of the box, the animation wants to go to the zero'd out transform of the parent(camera) whenever the animation is played. At the end of the animation, the sword returns to the child transform of the camera I set it to when I placed it. Immediately my eyes spotted "Apply Root Motion" and I gave it a tick to see what that would do. It did exactly what I wanted(well not quite), the sword was now swinging as intended from the correct position. But one problem.

    The problem was that if the animation was called in quick succession(Spamming Left mouse), the sword would sometimes animate beyond the animations transforms. If it entered this state, it would get stuck with the new transforms as their native state. ie: The sword swung 80 degrees. The glitch triggered and now 0 = 80 and the sword is now swinging from 80 to 160. Even holding that position when no animation is happening.

    Thoughts and tips on a better work flow on setting up weapons for First person cameras?