Preventing Wall Running

Ok so I am making a first person game when I jump and collide with the wall the character wallruns this issue occurs like this:
i am running and pressing W and jumped and the wall on the right or on the left the player wallruns along the wall i wrote a code to check for raycasthit on the left or the right and stop the player movement and make him fall but seems like it doesnt work well? like it works when i jump and press A key the player doesnt get stuck on the wall just falls anyways here is my movement script:

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

public class PlayerMovement : MonoBehaviour
{
    private Rigidbody playerRb;
    public float speed;
    public float jumpForce;
    public float gravityModifier;

    public Transform playerCamera;
    private Vector3 moveDirection;

    private Camera playerCam;
    public bool isRunning;
    public bool isWalking;

    // Start is called before the first frame update
    void Start()
    {
        playerCamera = GameObject.Find("Camera").GetComponent<Transform>();
        playerRb = GetComponent<Rigidbody>();
        playerRb.freezeRotation = true;
        Physics.gravity *= gravityModifier;
        playerCam = GameObject.Find("Camera").GetComponent<Camera>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        playerMovement();
        transform.rotation = Quaternion.Euler(0, playerCamera.transform.eulerAngles.y, 0);
    }
    void Update()
    {
        playerJump();
        zoomIn();
    }

    void playerMovement()
    {
        isWalking = false;
        isRunning = false;

        if (moveDirection != Vector3.zero)
        {
            if (Input.GetKey(KeyCode.LeftShift))
            {
                speed = 10;
                isRunning = true;

            }
            else
            {
                speed = 5;
                isWalking = true;
            }
        }
        float horizontalInput = Input.GetAxisRaw("Horizontal");
        float verticalInput = Input.GetAxisRaw("Vertical");

        // Get the forward and right vectors from the camera
        Vector3 cameraForward = playerCamera.transform.forward;
        Vector3 cameraRight = playerCamera.transform.right;

        // Remove the y-component from forward and right, since we want 2D movement relative to the ground
        cameraForward.y = 0;
        cameraRight.y = 0;

        // Normalize the vectors
        cameraForward.Normalize();
        cameraRight.Normalize();

        // Calculate movement direction based on camera's forward and right
        moveDirection = (cameraForward * verticalInput) + (cameraRight * horizontalInput);
        moveDirection.Normalize(); // Normalize to ensure consistent movement speed

        RaycastHit wallDetect;

        if (Physics.Raycast(transform.position, transform.right, out wallDetect, 1.1f))
        {
            if (wallDetect.collider)
            {
                playerRb.velocity = new Vector3(0, playerRb.velocity.y, 0);
                return;
            }
        }

        playerRb.velocity = new Vector3(moveDirection.x * speed, playerRb.velocity.y, moveDirection.z * speed);
    }

    void zoomIn()
    {
        float targetFOV = 30;
        float velocity = 0;
        float currentFOV = playerCam.fieldOfView;

        if (Input.GetKey(KeyCode.Mouse1))
        {
            playerCam.fieldOfView = Mathf.SmoothDamp(currentFOV, targetFOV, ref velocity, 0.06f);
        }
        else
        {
            playerCam.fieldOfView = Mathf.SmoothDamp(currentFOV, 60, ref velocity, 0.06f);
        }
    }

    void playerJump()
    {
        if (Input.GetKeyDown(KeyCode.Space) && isGrounded())
        {
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        }
    }



    public bool isGrounded()
    {
        return Physics.Raycast(transform.position, Vector3.down, 1.1f);
    }
}

That just sounds like you wrote yourself a bug… and that means… time to start debugging!

Staring at code that interoperates closely with physics and the built environment is not going to be super-useful. You’ll get the most progress by proper debugging and perhaps even some custom instrumentation to identify what walls things are connected to, running on, etc.

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.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

Try not setting velocity directly on the player/rigidbody. Your jump code uses AddForce(), but if you set velocity in another spot, that can cause unexpected behavior. So line 90, use AddForce() instead (and tweak magnitude as needed, it’ll be a lot different most likely). Comment out all the wall detection, it shouldn’t be needed. Does it work then? The player should hit the wall and fall with gravity.

Avoiding GameObject.Find() is also recommended for a variety of reasons. Just assign the Camera to playerCamera in the Inspector. Then you can delete line 22, and line 26 would be playerCam = playerCamera.GetComponent<Camera>();