I am using the translate method to move a camera to a relative position. To make this look smooth, the relative position is lerp’d over time. Basically,
transform.Translate(Vector3.Lerp(new Vector3(0,0,0), newPos, Time.deltaTime));
I’m try to work out a condition to allow me to stop the translation happening, once the transform reaches somewhere near newPos
. Something like,
if (Vector3.Distance(transform.position, oldPosition + newPos) < 5) {
//Stop moving the object
newPos = new Vector3(0,0,0);
}
Vector3.Distance
doesn’t work because oldPosition+newPos
does not necessarily point to the same position as it is translating to.
What I really need is a way of returning the result of where a translation will end up, without actually moving the object itself.
Edit: This system is used for moving a camera based on a swipe, and newPos
is calculated from a fixed movement, e.g.
if (/*swipe conditions and direction check*/) {
newPos.y += 100;