Movement of my player is currsed

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

public class NewTheirdPersonn : MonoBehaviour
{

    //public
    public CharacterController controller;

    public Transform cam;

    public float myGravity = 9.81f;

    public float speed = 6f;

    public float turnSmoothTime = 0.1f;

   

    float turnSmoothVelocity;

    //private
    public Animation Anim;
    private Animator Animator;
    private Rigidbody rb;


    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
        if (!controller.isGrounded)
            rb.AddRelativeForce(Vector3.down * myGravity);
       
    }

    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;

        if (!controller.isGrounded)
            direction = new Vector3(horizontal, 0f, vertical);

        if (direction.magnitude >= 0.1f)
        {
            float targetAngel = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngel, ref turnSmoothVelocity, turnSmoothTime);
            transform.rotation = Quaternion.Euler(0f, angle, 0f);

            Vector3 moveDir = Quaternion.Euler(0f, targetAngel, 0f) * Vector3.forward;
            controller.Move(moveDir.normalized * speed * Time.deltaTime);

           

        }



    }
}

here I do have a Skript vor my movement and the traking for my third person camera. Now I have the problem that my Gravity doesent work very well. The problem is when I move my and if I am over a spot that is lower that the spawnpoint then the character in my game flys over the spot if I still hold my Key “W”. If I let it go the character drops on the Layer down. But if I hold “W” again it goes on to the same Y koordinates like the Spawnpoint and the Character Flys again. Does anyone have an idea what in the code has to be changed to fix this problem?

As far as I know, Character Controller component isnt compatible with physics system and will ignore any Rigidbody forces when it is moving. You need to either find a way to incorporate gravity into CharacterController.Move input vector, or code a new fully Rigidbody based controller.

Other things to note: gravity is acceleration, not a constant force, so it should be more like storing a Vector3 as variable and adding to it every frame (reset the vector to zero while on ground). And AddRelative force works using local coordinates of your object. Isnt relevant in this situation, but can create problems in other cases.

Thx for the tipps I’ll try to fix it with thoes ideas. have a nice Day