About how to escape from the water surface

Sorry, please help me
I’m having trouble handling it when I get out of the water.
The code looks like this

private void OnTriggerStay(Collider other)
{
Renderer otherRenderer = other.gameObject.GetComponent();
if (otherRenderer == null) return;

Material material = otherRenderer.sharedMaterial;
MaterialProperties properties = materialManager.GetMaterialProperties(material);

if (properties != null)
{
if (properties.isWater)
{
waterSurface = other.GetComponent();
if (waterSurface != null)
{
float waterHeight = waterSurface.GetWaterHeight();
if (isClimbing)
{
if (waterHeight > transform.position.y + waterSetPos * 1.5f)
{
isGrippingCansel = true;
CanselCliming();
isSwiming = true;
isGrippingCansel = false;
}
else
{
CanselSwiming();
isClimbing = true;
}
}
else if(waterHeight > transform.position.y + waterSetPos * 1.5f)
{
isSwiming = true;
StopGlide();
}

}
}
else if (!properties.isWater)
{
if (isSwiming)
{
CanselSwiming();
}
}

}
}

void Swiming()
{
if (isSwiming&&IsGrounded)
{
Vector3 raypos = transform.position;
raypos.y = GetComponent().bounds.min.y;
RaycastHit hit;
if(Physics.Raycast(raypos, transform.forward,out hit, groundJugmentDistance))
{
Material groundMaterial = hit.collider.gameObject.GetComponent()?.sharedMaterial;
if (groundMaterial != null)
{
if (materialManager.GetMaterialProperties(groundMaterial).isGround)
{
CanselSwiming();
return;
}
}
else
{
isSwiming = true;
}
}

}
if (isSwiming)
{

float waterHeight = waterSurface.GetWaterHeight();
float depth = waterHeight - waterSetPos * 1.5f;
if (transform.localPosition.y + waterSetPos < waterHeight)
{

rb.useGravity = false;
rb.DOMoveY(depth, 1.0f);
Vector3 cameraForward = mainCamera.transform.forward;
Vector3 cameraRight = mainCamera.transform.right;
cameraForward.y = 0f;
cameraRight.y = 0f;
cameraForward.Normalize();
cameraRight.Normalize();

Vector3 desiredMoveDirection = cameraForward * movePos.z + cameraRight * movePos.x;
desiredMoveDirection.Normalize();
if (desiredMoveDirection != Vector3.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(desiredMoveDirection);
transform.DORotateQuaternion(targetRotation, characterGaridRotateDuration);
}
rb.linearVelocity = new Vector3(desiredMoveDirection.x * swimingSpeed, 0, desiredMoveDirection.z * swimingSpeed);
}

}

What’s bothering me is that when I try to escape from the surface of the water, I can’t move as if I’m stuck.
It starts moving after a while, but there is a pause and it feels uncomfortable.
On the other hand, entering the water works fine.
I want to eliminate this gap
It’s a Google translation, so there may be some mistakes in the English, so please help if you don’t mind.

It sounds like you wrote a bug… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly