How to change animation speed in blend tree by script?
Asked Answered
T

3

0

I want to set “This” value in the screenshot by script.Is there any way?Please23173-toask.png

Tumbler answered 24/1 at 10:33 Comment(1)

Was asked there as well. https://mcmap.net/q/40577/unity-how-to-access-blend-tree-speed-in-mecanim-from-c

Ita
A
0

This answer may be a little late, but I wanted to achieve the same thing and this is how I accomplished it.

In my Blend Tree, I added the same animation with a lower Animation Speed.
Notice how I have the walk motion twice. One with the speed set to 1 and another with the speed set to 0.5


This allows me to slow the walking animation if the player is pressing lightly on the joystick and speeds the animation up if the player presses the joystick harder.


I added a float parameter called speedPercent. In my code, I change the speedPercent by using:

public Animator animator;

float speedValue;
if( walkingSlow ) speedValue = 0.3f;
else if( walkingFast ) speedValue = 0.6f;
else if( running ) speedValue = 1f;
else speedValue = 0f;
animator.SetFloat( "speedPercent" , speedValue );

This code is just an example, it is not the actual code.

Adulate answered 24/1 at 10:37 Comment(0)
S
0

The animator speed property do this, but the animator speed work with all animations, so you have to change the speed for all animations in animator controlling them, for example, if your player movement, need to change the animation speed to run clip and want the animation more faster, you must change the animator.speed to 2. After this when you need to back speed, change the speed back to 1 in idle animation or other animation.

private Animator animator;
animator.speed = value;
Straus answered 24/1 at 10:38 Comment(0)
D
0

image
all you need change

Deliver answered 24/1 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.