I want my player to aim up and down with a pistol. I have stored an "aim up" pose in one anim file, and I have stored an "aim down" pose in another anim file. I want to blend between these 2 poses according to the mouse pointer on the screen:
- If the mouse pointer is at the bottom of the screen, the blend tree should only play the "aim down" pose
- If the mouse pointer is at the top of the screen, the blend tree should only play the "aim up" pose
- If the mouse pointer is at the middle of the screen, the blend tree should play a 50/50 mix of the "aim down" and of the "aim up" pose
To do that, I have added a 1D blend tree to my animator.
It looks like this:
I have tested the blend tree. When I scrub through the "timeline" using the red line, it works as expected:
Now I wanted to test it out in my game, but I don't see how to set the blend weight of this 1D blend tree.
The docs say that the blend tree is controlled by the animation parameters.
As far as I can see, Unity automatically created one for me when I added the blend tree. The name seems to be "Blend", as can be seen in the screenshot:
The following however has no visual effect for me:
_animator.SetFloat("Blend", 1f);
To check if this parameter even exists, I have changed its value to 0.3 in the animator.
Then in my code, I check the value like this, and it does return 0.3:
float fCur = _animator.GetFloat("Blend");
So this is proof that the parameter does exist. However, when I set a new value like...
_animator.SetFloat("Blend", 0.56f);
... then this value is accepted, but it doesn't have any visual effect, and it doesn't show in the animator's paramters.
Can anybody tell me how I could achieve what I want?
Edit:
I have tested it in a new, stripped-down project. In this new project, I have the blend tree as the default state in the animator, and everything works.
So the fact that my blend tree is NOT the default state in the other project seems to be the problem. This is what it looks like:
I will first try to investigate more on this.