So I’ve been playing with using Vector3 to move things around in my environment (primatives, the camera etc). I was originally having an issue where my objects just NEVER quite got to where they where supposed to be. They would approach the destination and then they would SLOWLY start to crawl.
I’ve been looking into this for a while and using the docs I found out that the t value in the Vector3.Lerp method was clamped between 0-1 where 0=to and 1=from. Using that logic I figured that my previous Lerp attempts where simply moving an almost imperceptible measure every frame towards the end. I wrote something that looks like the following that works much better. However I noticed that the object seems to reach it’s destination long before my position float hits 1. Why is this?
void Update () {
if (pos < 1) {
moveIt();
}
tgui.text = pos.ToString();
}
void moveIt () {
transform.position = Vector3.Lerp(transform.position, new Vector3(target.position.x + offset, 3, target.position.z), pos);
pos += lerpSpeed;
}