Rebound losing energy

Hi, I’ve been trying to fix my problem for quite some time and I still can’t so I hope someone here will be able to.
I’ve go a falling Rigidbody2D (without velocity at start), with y positive :

    void Start()
    {
        rigidbody2d = transform.GetComponent<Rigidbody2D>();
    }

When reaching y = 0, I want it to “rebound” (in thin air), for that, I only invert the velocity.y :

    private void Update()
    {
        if (rigidbody2d.position.y < 0f && rigidbody2d.velocity.y < 0f)
        {
            rigidbody2d.velocity = -Vector2.up*rigidbody2d.velocity.y;
        }
    }

My object shouldn’t lose energy at all because I’ve set all drags to 0. However, rebound after rebound, the objet goes less and less high.
I’d like it to be able to bounce at the same high every time. Obviously, FixedUpdate gives the same result.

If anyone knows what’s causing that effect and correct it, please tell me!
Thanks in advance

Hmm. Replace the velocity invert with:

        Vector3 velocity = rigidbody.velocity;
        velocity.y *= -1;
        rigidbody.velocity = velocity;

What you’re doing is only setting a velocity to the new Vector that will have the magnitude equal to previous velocity Y component, instead of being equal to previous velocity magnitude. If the velocity was not perfectly vertical, it will be less after your invert because you discarded X and Z components.

Disclaimer, I have not tested this. Lemme know if it works.