I'm still not get it how to mix/blend soldier character weapon aiming animation with walking animation ?

What i did so far:

  1. Created new animator controller for my third person character.
  2. Created a From New Blend Tree called it Movement and i did a Transition from the Entry to the Movement.
  3. Created a new State called it Aiming and assigned in as motion Rifle_Aiming_Idle
  4. Created two transitions from Movement to Aiming and from Aiming to Movement. From movement to aiming the conditions: Aiming True and from aiming to movement the conditions are: Aiming False.
  5. Inside the Movement blend tree i added two new motions: HumanoidIdle and Rifle_Aiming_Walk_F_RM
  6. Added parametersL Velx,Vely both float and also parameter name Aiming bool.
  7. HumanoidIdle set to 0 and 0 and Rifle_Aiming_Walk_F_RM is set to 0 and 1.

Then i attached to the character this script:

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

public class Soldier : MonoBehaviour
{
    private Animator anim;
    private bool aim = false;
    
    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 (aim == true)
        {
            anim.SetBool("Aiming", true);
            anim.SetFloat("VelX", inputVelx);
            anim.SetFloat("VelY", inputVely);
        }

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

    private void FootStep()
    {
        
    }
}

And the results:

When running the game the character start in idle state.
When i press the W key the character is walking forward and also aiming at the same time.
When i leave the W key the character is back to idle state without aiming.

If i click the mouse right button the character will aiming but will stay in aiming idle state if i press now W he will not move.

My main goal is how to make that when i click the mouse right button it will aiming and also when pressing W will walk. Now it’s only aiming but when i press W it’s not walking.

Screenshots:

The first is the parameters with the main layer: On the right you can see the state Aiming with that i’m doing the right mouse button click to get to aiming state and this is where i also want to make that if i press W it will also walk.

The second screenshot show the blend tree mixing the idle with the walking this part is working fine:

In other words i want to make that right mouse click i’m in aiming idle state and if i will press then the W key it will start walking if i leave the W key he will back to aiming idle state.

Try this:

 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);

     aim = Input.GetMouseButtonDown(1);

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

 }

You can set the aim but reading the mouse buttom, you don’t need to set it anywhere else. Also you only have to set the VelX and VelY parameters once according to the Horizontal and Vetical axis values.

Edit: You may also want to consider an avatar mask. If you only have a stationary aim animation then you can mask the legs and bottom half of the avatar so that you can play both the walking and aiming states together.