What i did so far:
- Created new animator controller for my third person character.
- Created a From New Blend Tree called it Movement and i did a Transition from the Entry to the Movement.
- Created a new State called it Aiming and assigned in as motion Rifle_Aiming_Idle
- 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.
- Inside the Movement blend tree i added two new motions: HumanoidIdle and Rifle_Aiming_Walk_F_RM
- Added parametersL Velx,Vely both float and also parameter name Aiming bool.
- 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.