How do i use the animator avatar mask to combine two animations?

623 views Asked by At

I want to combine weapon aiming idle with humanoidwalk. So in the script when i click on the mouse right button it will aim and then when i press W it will start walking.

Now with the animator controller and script i have i can make right click on the mouse button and it will aiming but won't walk or i can just press W and it will walk with aiming. But i want to first right click and aiming and then press W and walk.

The screen shot is on my main layer the base layer: The Aiming state is with weapon idle animation. And two transitions using parameter name Aiming type bool one transition set to true the other to false. With this i can make right click button on mouse and aiming but not walking.

Base Layer

The second screenshot show the blend tree i did when making double click on Movement it's getting to the blend tree: Using this blend tree with the script when i press on W it will walk and aiming the same time.

Blend Tree

Now i tried to create a new layer with a avatar mask to make that when i click mouse right button it will first aim and then when pressing W it will walk. But it's not working.

In this layer i have only weapon aiming idle state with the weapon idle animation. What should i do here else ? And what should i add/change in the script ?

Toroso

The script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Soldier : MonoBehaviour
{
    private Animator anim;

    private void Start()
    {
        anim = GetComponent<Animator>();
    }

    void Update()
    {
        var inputVelx = Input.GetAxis("Horizontal");
        var inputVely = Input.GetAxis("Vertical");

        transform.Rotate(0, inputVelx, 0);

        anim.SetFloat("VelX", inputVelx);
        anim.SetFloat("VelY", inputVely);

        if (Input.GetMouseButtonDown(1))
        {
            anim.SetBool("Aiming", !anim.GetBool("Aiming"));
        }
    }

    private void FootStep()
    {

    }
}

The main goal: To be able to click on mouse right button for aiming and then pressing W and walking.

0

There are 0 answers