Daniel Lip
Daniel Lip

Reputation: 11319

What is wrong with the AnimationCurve ? The lerp duration never change

I I set the lerp to 1 or to 10 the transform is moving to the target too fast.

At the top :

public AnimationCurve curve = AnimationCurve.Linear(0.0f, 0.0f, 1.0f, 1.0f);
public float duration = 10.0f;
private float t;

At Start()

void Start()
    {
        t = 0.0f;
    }

At Update()

void Update()
    {
        switch (state)
        {
            case TransitionState.MovingTowards:
                var v = targetTransform.position - transform.position;
                if (v.magnitude < 0.001f)
                {
                    state = TransitionState.Transferring;
                    originTransform = targetTransform;
                    timer = 0;
                    return;
                }
                t += Time.deltaTime;
                float s = t / duration;
                transform.position = Vector3.Lerp(transform.position,
                    targetTransform.position, curve.Evaluate(s));
                break;
        }
    }

The curve animation in the editor :

Curve animation in editor inspector

Upvotes: 0

Views: 309

Answers (1)

Patrick Scheper
Patrick Scheper

Reputation: 26

You seem to lerp from Transform.Position to your TargetPosition. That means that everytime you move you lerp from a new starting position. This will make your object move exponantially. Try lerping from a fixed start position to a fixed end position. (Unless this is what you actually want to happen)

If I read your code correctly your duration is the exact duration in seconds that your lerp should take. So I assume that's correct, just fix the "start" position of your lerp.

Upvotes: 1

Related Questions