Created
March 31, 2015 19:26
-
-
Save dnkm/c7ba798610217cb261b6 to your computer and use it in GitHub Desktop.
Unity Mathf.lerp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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