Bounce off boundary bug

HI, I’m pretty new to Unity and coding and i have this problem while coding an effect of bouncing a text object off the wall (screen boundary ).
Kind of like the display on the DVD player when not used, just kept bouncing around.

But he bug here is that it sometimes gets out of the bound that I set and just stopped there, or sometimes went quivering and continued in an irrational direction.

Here is my code, it’s the simplest way i could think of to do it

transform.Translate(velocity*Time.deltaTime);
        if (transform.position.x >= GetBoundary._MAX_X || transform.position.x <= GetBoundary._MIN_X)
        {
            velocity = Vector2.Reflect(velocity, new Vector2(1, 0));
            velocity *= 0.8f;
        }
        if (transform.position.y >= GetBoundary._MAX_Y || transform.position.y <= GetBoundary._MIN_Y)
        {
            velocity = Vector2.Reflect(velocity, new Vector2(0, 1));
            velocity *= 0.8f;
        }

Thanks a lot for answering.

If you are beyond the bounds, you are simply reflecting the velocity for the rebound but you don’t ensure that you are back within the bounds therefore it’s easily possible that the object will stay beyond the bounds if the reflected velocity isn’t high enough to move it within the bounds on the next update.

You should ensure that the position is within the bounds as well as reflecting the velocity. One way to reposition it within the bounds is to move it backwards using inverse the velocity i.e. project the position back to the bounds along the velocity vector.