Animator state playing stop after lerping. How to continue the playing ?

When the lerping is over and t value reached 1 the anim.Play stop playing the state animation.
Instead it should keep playing it on maximum value.

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

public class MoveTurn : MonoBehaviour
{
    public float moveSpeed;
    public float rotationSpeed;

    private Animator anim;
    public float minimum = 0.0F;
    public float maximum = 1.0F;
    public float duration;

    // starting value for the Lerp
    private float t = 0.0f;

    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed);

        t += Time.deltaTime / duration;
        float value = Mathf.Lerp(minimum, maximum, t);
        anim.Play("Walk",0,value);
    }
}

I’ve never seen animation attempted this way.

Usually you let the animation itself loop but you are preventing that by supplying value equal to maximum every frame after the lerp finishes up.

You may wish to review the basic MecAnim setup tutorials… They usually just change properties on the Animator, such as .SetFloat("Speed", speed); for example.

And of course you make that State use a float parameter to control its speed.

Here’s an example where I use my “Speed” parameter… this is within the animator State for my walk.

8202819--1070217--Screen Shot 2022-06-13 at 3.29.54 PM.png

1 Like

Working. thanks.

1 Like