Really unexpected with player movement

can anyoine help me with my player movement ive been at it for 24 hours and chatgpot wont help

using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerCamera : MonoBehaviour
{
    [SerializeField] private float rotationSpeed = 1.5f; // Adjust the rotation speed as needed
    [SerializeField] private float upDownSpeed = 1.5f; // Adjust the up and down rotation speed as needed
    [SerializeField] private float maxUpDownAngle = 80.0f; // Maximum angle for up and down rotation



    private void Start()
    {

        // Optional: Lock and hide the cursor to prevent it from leaving the screen.
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    private void Update()
    {
        // You can add camera-related updates here if needed.
    }

    public void Look(InputAction.CallbackContext context)
    {
       
        transform.parent.transform.Rotate(new Vector3(0f, context.ReadValue<Vector2>().x * 0.1f* rotationSpeed, 0f));

        // Rotate the camera on the X-axis based on mouse input (vertical movement).  transform.localRotation = Quaternion.Euler(verticalRotation, horizontalRotation, 0);
        transform.Rotate(new Vector3(math.clamp(context.ReadValue<Vector2>().y * 0.1f * upDownSpeed, -maxUpDownAngle, maxUpDownAngle) * -1, 0f, 0f));
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] private float moveSpeed = 5.0f; // Speed at which the player moves.
    [SerializeField] private float moveSpeedMultiplier = 2.0f; // Speed at which the player moves.
    [SerializeField] private float jumpForce = 10.0f; // Force applied when jumping.
    private Rigidbody rb;
    private bool isGrounded; // Flag to check if the player is grounded.
    private Vector3 moveDirection;
    private bool canSprint;
    private bool isSprinting = false;
    void Start()
    {
        rb = gameObject.GetComponent<Rigidbody>();
    }

    void Update()
    {
        // Check if the player is grounded.
        isGrounded = Physics.Raycast(transform.position, Vector3.down, 1f);

        if (moveDirection != Vector3.zero)
        {  
           
            moveDirection = transform.forward * moveDirection.z + transform.right * moveDirection.x;

           
            rb.velocity = moveDirection;
            Debug.Log(moveDirection);
        }
       
       
    }

    public void Move(InputAction.CallbackContext context)
    {
        // Get the input direction.
       

        // Calculate the movement direction relative to the camera's forward direction.
        moveDirection = new Vector3(context.ReadValue<Vector2>().x, 0f, context.ReadValue<Vector2>().y);
        moveDirection.y = 0;
        moveDirection *= moveSpeed;
       
       
       
       
       
    }
    public void Jump(InputAction.CallbackContext context)
    {
        if (isGrounded && context.performed)
        {
            rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        }
        Debug.Log("jump");
    }
   
}

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you have no idea what your code is doing, fix that first. Here’s how:

Time to start debugging! Here is how you can begin your exciting new debugging adventures:

You must find a way to get the information you need in order to reason about what the problem is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the names of the GameObjects or Components involved?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as Debug.Log("Problem!",this);

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer for iOS: How To - Capturing Device Logs on iOS or this answer for Android: How To - Capturing Device Logs on Android

If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

If your problem is with OnCollision-type functions, print the name of what is passed in!

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

“When in doubt, print it out!™” - Kurt Dekker (and many others)

Note: the print() function is an alias for Debug.Log() provided by the MonoBehaviour class.

If you just need a basic FPS script, try this one:

That one has run, walk, jump, slide, crouch… it’s crazy-nutty!!

ok soo ive been trying different out come the movement worked until i tried to implement going forward based on player direction i got multiple random results (going around in circles) and chat gpt wouldt help at all i just need a good formula to determine moveDirection based on player rotation (i think im completly wrong on line 29 playermovement but thats wht chatgpt game me so idk

See steps above. They will help you fix the “idk” part of your problem.

you could please help that surprisingly does not help since it is a logic error

Debugging is for logic errors. Only you can see those logic errors, not us.

If you are simply not interested in debugging, that’s fine. Reach for one of the pre-made solutions such as the BasicFPCC that I linked for you above.

Otherwise, refer to the debugging steps above to learn more about what your code is doing.

Once you have more insight, again, here is how to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

it’s not a logic problem…

i do think it is as the player simple decides to only move in positive directions and spin around the camera for no reason