Skip to content

Instantly share code, notes, and snippets.

@dnkm
Created March 31, 2015 19:26
Show Gist options
  • Save dnkm/c7ba798610217cb261b6 to your computer and use it in GitHub Desktop.
Save dnkm/c7ba798610217cb261b6 to your computer and use it in GitHub Desktop.
Unity Mathf.lerp
// constant movement
void Update() {
transform.position = Vector3.Lerp(pos1.position, pos2.position, speed * timer);
if (destination == pos1) {
timer = Mathf.Clamp(timer = Time.deltaTime, 0.0f, 1.0f/speed);
} else {
timer = Mathf.Clamp(timer + Time.deltaTime, 0.0f, 1.0f/speed);
}
}
// accelerates then slows down.
void Update() {
transfrom.position = Vector3.Lerp(transform.position,
destination.position,
speed * 3.0f * Time.deltaTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment