So I need to have an object confined to moving around only in the y axis between the top and bottom edges of the screen. This is what I have:
Vector3 viewPos = Camera.main.WorldToViewportPoint(transform.position);
viewPos.y = Mathf.Clamp01(viewPos.y + .128f);
viewPos.y = Mathf.Clamp01(viewPos.y - .128f);
transform.position = Camera.main.ViewportToWorldPoint(viewPos);
This doesn’t work because for some reason, the clamp is only working at the top edge of the screen. At the bottom edge, it still allows half of the object to go through before stopping it. Why would this be?