My player is not moving forward i had to update the code and it stopped

Here is my code my player was moving forward backwards and everything but animations weren’t playing then I found out why can somebody tell me why my player wont move now

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

public class ThirdPersonPlayerController : MonoBehaviour
{
    private const string @bool = "IsWalking";
    private const float RotationSpeed = 10f;
    public Transform playerTransform;
    public Transform orientation;
    public Animator animator;
    public Rigidbody rb;

    public float rotationSpeed = 15f;
    public float moveSpeed = 6f;
    public float groundDrag = 6f;
    public float airDrag = 2f;
    public float jumpForce = 10f;

    public LayerMask whatIsGround;
    public float playerHeight = 2f;

    float horizontalInput;
    float verticalInput;
    bool jumpInput;

    Vector3 moveDirection;
    Vector3 velocity;
    bool grounded;

    public float sensitivity = 2.0f;   // Mouse sensitivity
    public Transform characterBody;    // Character's body or root transform
    float xRotation = 0.0f;

    public UnityEngine.UI.Slider healthSlider; // Reference to the health bar slider U
    // Health related variables
    public int maxHealth = 100;
    private int currentHealth;
    private Vector3 speed;
    private bool isWalking;
    private bool isRunning;
    private object Q;
    private int newWeaponIndex;
    private int nextFireTime;
    private readonly object w;

    void Start()
    {
        rb.freezeRotation = true;
    }

    void fupdate()
    {
        GetInput();
        HandleOrientation();
        HandleMovementInput();
        HandleDrag();
        HandleJump();
        StartWalking();
        StopWalking();
        IsWalking();
        StartRunning();
        StopRunning();
        IsRunning();
        MovePlayer();;
        Health();
        UpdateAnimator();
        Animation(); // Added for animation
        CheckGround();
    }

    private void Animation()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity;
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput = Input.GetAxis("Vertical");

        characterBody.Rotate(Vector3.up * mouseX);

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90.0f, 90.0f);
        transform.localRotation = Quaternion.Euler(xRotation, 0.0f, 0.0f);

        animator.SetBool("Walk", Mathf.Abs(verticalInput) > 0f);
        animator.SetBool("Run", Input.GetKey(KeyCode.LeftShift) && Mathf.Abs(verticalInput) > 0f);

        if (Input.GetKeyDown(KeyCode.P))
        {
            animator.SetTrigger("RightPunch");
        }

        if (Input.GetKeyDown(KeyCode.L))
        {
            animator.SetTrigger("LeftPunch");
        }

        if (Input.GetKeyDown(KeyCode.K))
        {
            animator.SetTrigger("Kick");
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            animator.SetBool("Crouch", true);
        }
        else if (Input.GetKeyUp(KeyCode.C))
        {
            animator.SetBool("Crouch", false);
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            animator.SetTrigger("Shoot");
        }

        if (Input.GetButtonDown("space"))
        {
            animator.SetTrigger("Jump");
        }

        if (Input.GetButtonDown("RightShift"))
        {
            animator.SetTrigger("ChangeWeapon");
        }
    }


    private void Health()
    {
        // Initialize health
        currentHealth = maxHealth;

        // Set up the health slider
        healthSlider.maxValue = maxHealth;
        healthSlider.value = maxHealth;

        // Lock cursor to center of the screen
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;

        // Other existing code...
    }
    void fixedupdate()
    {
        // Other existing code...
        HandleMovementInput();
        MovePlayer();
        // Other existing code...
    }

    void MovePlayer()
    {
        // Convert the move direction relative to the camera's orientation
        moveDirection = playerTransform.TransformDirection(moveDirection);
        moveDirection.y = 0.0f; // Ensure the player stays at the same height

        // Calculate move velocity based on move direction and speed
        Vector3 moveVelocity = moveDirection * moveSpeed;

        // Move the player using Rigidbody
        rb.MovePosition(rb.position + moveVelocity * Time.deltaTime);

        // Update the velocity only if grounded
        if (grounded)
        {
            velocity = rb.velocity;
            rb.velocity = new Vector3(moveVelocity.x, rb.velocity.y, moveVelocity.z);
        }
        else
        {
            // If not grounded, maintain the current vertical velocity to allow jumping/falling
            rb.velocity = new Vector3(moveVelocity.x, velocity.y, moveVelocity.z);
        }
    }


    private void StartWalking()
    {
        {
            isWalking = true;
            Console.WriteLine("Animation: Start Walking.");
        }
    }

    private void StopWalking()
    {
        isWalking = false;
        Console.WriteLine("Animation: Stop Walking.");
    }

    private bool IsWalking()
    {
        return isWalking;
    }

    private void StartRunning()
    {
        {
            isRunning = true;
            Console.WriteLine("Animation: Start Running.");
        }
    }

    private void StopRunning()
    {
        isRunning = false;
        Console.WriteLine("Animation: Stop walking.");
    }

    private bool IsRunning()
    {
        return isRunning;
    }

    void GetInput()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput = Input.GetAxis("Vertical");
        jumpInput = Input.GetButtonDown("Jump");
    }

    void HandleOrientation()
    {
        float mouseX = Input.GetAxis("Mouse X") * sensitivity;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity;

        // Rotate player around the Y-axis based on mouse input
        playerTransform.Rotate(Vector3.up * mouseX);

        // Rotate camera orientation around the X-axis based on mouse input
        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90.0f, 90.0f);
        orientation.localRotation = Quaternion.Euler(xRotation, 0.0f, 0.0f);
    }

    void HandleMovementInput()
    {
        // Get input values
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput = Input.GetAxis("Vertical");

        // Calculate move direction based on camera orientation
        Vector3 forward = orientation.forward;
        Vector3 right = orientation.right;

        // Project camera direction onto the horizontal plane
        forward.y = 0f;
        right.y = 0f;
        forward.Normalize();
        right.Normalize();

        // Calculate move direction based on input and camera orientation
        moveDirection = forward * verticalInput + right * horizontalInput;
        moveDirection.y = 0f; // Ensure the player stays on the same level
        moveDirection.Normalize(); // Normalize to prevent faster diagonal movement
    }


    void HandleDrag()
    {
        float drag = grounded ? groundDrag : airDrag;
        rb.drag = drag;
    }

    void HandleJump()
    {
        if (jumpInput && grounded)
        {
            rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        }
    }

    void CheckGround()
    {
        // Use a raycast to check if the player is grounded
        grounded = Physics.Raycast(playerTransform.position, Vector3.down, playerHeight / 2 + 0.2f, whatIsGround);
        Debug.Log("Grounded: " + grounded);
    }

    void UpdateAnimator()
    {
        // Update animator parameters
        animator.SetFloat("Speed", Mathf.Clamp01(Mathf.Abs(horizontalInput) + Mathf.Abs(verticalInput)));
        animator.SetBool("IsGrounded", grounded);
    }
}
  1. Update Loop Naming:

    • Unity recognizes Update, FixedUpdate, and LateUpdate as specific functions with predefined behavior. In your code, you have fupdate and fixedupdate, which won’t be called automatically by Unity. Change them to Update and FixedUpdate:

      // void fupdate()
      void Update()
      {
          // Your existing code...
      }
      
      // void fixedupdate()
      void FixedUpdate()
      {
          // Your existing code...
      }
      
  2. Incorrect Key Input Check:

    • You are checking for the “space” key using Input.GetButtonDown("space"), but it should be Input.GetButtonDown("Jump") based on your current input setup:

      if (Input.GetButtonDown("Jump"))
      {
          animator.SetTrigger("Jump");
      }
      
  3. Unused Variables:

    • Remove unused variables like speed, newWeaponIndex, nextFireTime, and w to declutter your code.