I want to move a cube A to another cube B using Lerp, but only if the distance between them is greater than 2.0f. But since Lerp is applied in multiple Update() frames, in the next Update() the distance between the two cubes is 1.9 for example, and the code doesn´t enter in the if statment and the cube A just stops there.
How could I move the cube A to cube B?
void Start()
{
startPos = transform.position;
}
void Update()
{
float distance = Vector3.Distance(transform.position, nextStepPos.position);
if (distance > 2.0f)
{
transform.position = Vector3.Lerp(transform.position, nextStepPos.position, speed * Time.deltaTime);
}
else
{
transform.position = startPos;
}
}