'How can I stop my player from floating up of the map?

I've been following a tutorial for movement and this problem came up at the end with the Jump feature. The problem seems to be that the jump makes the character fly up off the map. my code is from https://www.youtube.com/watch?v=_QajrabyTJc because I am new to unity. this is how it looks.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playermovment34 : MonoBehaviour
{
public CharacterController controller;

public float speed = 12f;

Vector3 velocity;

public float gravity = -9.81f;

public float jumpHeight = 3f;

public Transform groundCheck;

public float groundDistance = 0.4f;

public LayerMask groundMask;

bool isGrounded;


// Update is called once per frame
void Update()
{
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

    if (isGrounded && velocity.y < 0) ;
    {
        velocity.y = -2f;

    }



    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;

    controller.Move(move * speed * Time.deltaTime);

    if (Input.GetButtonDown("Jump") && isGrounded) ;
    {
        velocity.y = Mathf.Sqrt(jumpHeight * - 2f * gravity);
        
    }

    velocity.y += gravity * Time.deltaTime;

    controller.Move(velocity * Time.deltaTime);




}
}

Thanks for any help.



Solution 1:[1]

You're multiplying gravity by Time.deltaTime in two separate locations (before and after it's added to velocity), which will make it extremely small. Change:

velocity.y += gravity * Time.deltaTime;

to:

velocity.y += gravity;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sven Viking