I am trying to make my object float up and then down in a loop .
I use Vector3.SmoothDamp to make it go in the up but I do not seem to be able to find out when it has reached its location.
I use this code to check if it has reached it location but it only log the “0” at start and not when it has stoped moving
If transform.position == moveToYPosition within some error range. You can rely on Unity’s error factor and just use:
if (transform.position == moveToYPosition)
or you can invent your own standard of “close enough”
Vector3 diff = transform.position-moveToYPosition;
// we will use sqrMagnitude to avoid costly square roots
// so if we need them to be within .01 of each other,
// we check against .0001 (.01*.01)
if (diff.sqrMagnitude < .0001)
// code for clamp being done