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");
}
}