Bolt
July 10, 2017, 9:42am
1
Can I rewrite the Lerp function? By doing so the movement is flickering
private Vector3 MyLerp(float t, Vector3 p0, Vector3 p1)
{
return p0 + t * (p1 - p0);
}
// Update is called once per frame
void Update () {
tr.transform.position = MyLerp(Time.deltaTime, point0.position, point1.position);
}
Baste
July 10, 2017, 9:45am
2
Your rewritten lerp function is correct, but you’re invoking it wrong. You’re positioning tr at a point Time.deltaTime between point0 and point1. That’s going to be some arbitrary point close to point0, which will vary based on your frame rate.
Here’s a good writeup on how to lerp correctly.
jister
July 10, 2017, 11:16am
3
void Update () {
float lerp +=Time.deltaTime;
Mathf.Clamp01(lerp);
tr.transform.position = MyLerp(lerp, point0.position, point1.position);
}
Clamp is a function that returns the clamped value. They way you’re calling it here will do nothing.
jister
July 10, 2017, 1:36pm
5
you’re right. Did it in a hurry. also you can not declare and increment a variable like that.
public float speed = 0.5f;
float lerp;
void Update () {
lerp +=Time.deltaTime*speed;
tr.transform.position = MyLerp(Mathf.Clamp01(lerp), point0.position, point1.position);
}
or
lerp = Mathf.Clamp01(lerp);
1 Like