- Home /
Question by
cambo2015 · Dec 16, 2017 at 09:19 PM ·
controllerplayer movement
Stop walking while in air with Animator.setFloat()
I'm trying to make my player jump in the air. A bool named isGrounded is set to false when I jump. However, when I move my character and then jump while still holding the arrow key down, the jumping the animation keeps going. The animation does disable when I only press the jump key first and then press the arrow buttons. Any help is appreciated! Thanks in advance!
void WalkAnim(float h, float v)
{
if (scriptGrounded.isGrounded)
{
Debug.Log("is Walking");
float smoothTransitionTime = .001f;
anim.SetFloat(vHash, h, smoothTransitionTime, Time.deltaTime);
anim.SetFloat(hHash, v, smoothTransitionTime, Time.deltaTime);
}
}
Comment
Answer by cambo2015 · Dec 16, 2017 at 09:44 PM
I answered my own question haha. Here is my solution for those that need it :
void WalkAnim(float h,float v) {
float temp_H = h;
float temp_V = v;
float smoothTransitionTime = .001f;
if (scriptGrounded.isGrounded == false )
{
anim.SetFloat(vHash, 0f, smoothTransitionTime, Time.deltaTime);
anim.SetFloat(hHash, 0f, smoothTransitionTime, Time.deltaTime);
}
else if (scriptGrounded.isGrounded)
{
Debug.Log("is Walking");
anim.SetFloat(vHash, temp_V, smoothTransitionTime, Time.deltaTime);
anim.SetFloat(hHash, temp_H, smoothTransitionTime, Time.deltaTime);
}
}