How to make my player fall when the cursor is unlocked

Could some one help me out? I am trying to make my character fall down when my cursor is unlocked, but it goes all crazy and moves in random directions.

Player Controller:

public class PlayerCharactercontroller : NetworkBehaviour
{
[Header(“Player Controll”)]
public float MoveSpeed;
public float TurnSpeed;
public float JumpForce;
public float Gravity;

private CharacterController Controll;
private LockCursor Lock;

private float VerticalVelocity;

[SerializeField]
private Camera Cam;

void Start()
{
    Controll = GetComponent<CharacterController>();
    Lock = GetComponent<LockCursor>();
}

private void Update()
{
    if (!isLocalPlayer)
    {
        return;
    }

    if (Controll.isGrounded)
    {
        VerticalVelocity = -Gravity * Time.deltaTime;

        if (Input.GetKeyDown("space"))
        {
            VerticalVelocity = JumpForce;
        }
    }
    else
    {
        VerticalVelocity -= Gravity * Time.deltaTime;
    }

    Vector3 moveDir = new Vector3(0, VerticalVelocity, 0);
    moveDir.x = Input.GetAxis("Horizontal") * MoveSpeed;
    moveDir.y = VerticalVelocity;
    moveDir.z = Input.GetAxis("Vertical") * MoveSpeed;
    Controll.Move(transform.TransformDirection(moveDir) * Time.deltaTime);

    float _RotY = Input.GetAxisRaw("Mouse X");
    Vector3 _RotateY = new Vector3(0f, _RotY, 0f) * TurnSpeed;

    float _RotX = Input.GetAxisRaw("Mouse Y");
    Vector3 _RotateX = new Vector3(_RotX, 0f, 0f) * TurnSpeed;

    transform.Rotate(_RotateY);
    Cam.transform.Rotate(-_RotateX);
    
}

}

Lock:

public class LockCursor : MonoBehaviour
{
public bool Lock;

private void Start()
{
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.lockState = CursorLockMode.Confined;
    Cursor.visible = false;
    Lock = true;       
}

private void Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        if (!Lock)
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.lockState = CursorLockMode.Confined;
            Cursor.visible = false;
            Lock = true;
        }
        else
        {
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
            Lock = false;
        }
    }
}

}

What do you mean with fall down???

Do you mean your character is flying and if the cursor is unlocked he gets gravity??

if (Controll.isGrounded)
{
VerticalVelocity = -Gravity * Time.deltaTime;
if (Input.GetKeyDown(“space”))
{
VerticalVelocity = JumpForce;
}
}
else
{
VerticalVelocity -= Gravity * Time.deltaTime;
}

Have you noticed you’re applying gravity wherever you’re grounded or not?

if (Input.GetAxisRaw("Jump") != 0 && isGrounded) {

            VerticalVelocity = jumpForce;
        }

VerticalVelocity-= gravity * Time.deltaTime;
        moveDir.y = VerticalVelocity;

That code is very confusing…

//Vector3 moveDir = new Vector3(0, VerticalVelocity, 0);
 //moveDir.x = Input.GetAxis("Horizontal") * MoveSpeed;
 //moveDir.y = VerticalVelocity;
 //moveDir.z = Input.GetAxis("Vertical") * MoveSpeed;
 //Controll.Move(transform.TransformDirection(moveDir) * Time.deltaTime);

Vector3 moveDir = (Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))
moveDir *= MoveSpeed;
 Controll.Move(transform.TransformDirection(moveDir) * Time.deltaTime);