Combine Multiple Animations

I followed along the course used just the one animation, i thought i would use 2.
So I added a transition state between the two and also added a trigger, the same as the first one.

My problem remains, although i have the same bug of the animation keep continuing it will be fixed in the next lecture , there is also a problem where when he finally does stop hitting he does another 1 hit animation out of nowhere so im confused if i set it up completely wrong or if there is a better way to do it.


And instead of setting one trigger when I press to attack i trigger both

namespace RPG.Combat
{
    public class Fighter : MonoBehaviour, IAction
    {
        [SerializeField] float weaponRange = 2f;

        Transform target;

        private void Update()
        {
            //attacking behaviour
            if (target == null) return;
            if (!GetIsInRange())
            {
                GetComponent<Mover>().MoveTo(target.position);
            }
            else
            {
                GetComponent<Mover>().Cancel();
                AttackBehaviour();
            }
        }

        private void AttackBehaviour()
        {
            GetComponent<Animator>().SetTrigger("attack");
            GetComponent<Animator>().SetTrigger("attackRight");
        }

        private bool GetIsInRange()
        {
            return Vector3.Distance(transform.position, target.position) < weaponRange;
        }

        public void Attack(CombatTarget combatTarget)
        {
            GetComponent<ActionScheduler>().StartAction(this);
            target = combatTarget.transform;
        }

        public void Cancel()
        {
            target = null;
        }

        //Animation Event
        void Hit()
        {

        }
    }
}

Any help would be great. Thanks in advance

Changing the transition state from attack right back to locomotion instead of attack seems to have sorted the problem. Maybe not the most clean way so any advice would be appreciated but for now it works

If you’re always going to be doing both the attack and attack right in sequence, your transition from Attack to Attack Right just needs to be an empty transition with Has Exit Time checked.

If you’re doing something where you could have an Attack by itself or a combo attack with both, then I would create a second Attack state triggered by Attack Right that transitions to Attack Right.

Thanks Brian, So i was on the right track i suppose. This helps me alot for now, i fixed the transition by changing it to an empty with has Exit time Checked. It was working, but for what i want now it makes more since and i can always keep this in my mind, if i want to do something separate. As you said a combo attack or something down the line, I think I understand more.

Thanks

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms