Я могу переместить плеер, ссылаясь на это видео на YouTube. ПЕРВОЕ ДВИЖЕНИЕ ЧЕЛОВЕКА в Unity - FPS Controller
Однако, когда игрок прыгает, если направление движения - стена, игрок не может прыгнуть хорошо. вот так
Если я прыгаю с расстояния, я могу прыгнуть на стену.
Сценарий камеры:
public float mouseSensitivity;
[SerializeField]
Transform playerBody = default;
float xRotation = 0f;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
Сценарий движения:
[SerializeField]
CharacterController CharacterController = default;
[SerializeField]
LayerMask groundMask = default;
[SerializeField]
Transform groundCheck = default;
float groundDistance = 0.4f;
bool isGrounded = false;
public float playerSpeed;
public float playerGravity;
public float playerJumpSpeed;
Vector3 velocity;
private void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
velocity.y = -2f;
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
CharacterController.Move(move * playerSpeed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(playerJumpSpeed * -2f * playerGravity);
}
velocity.y += playerGravity * Time.deltaTime;
CharacterController.Move(velocity * Time.deltaTime);
}
Скажите, пожалуйста, кому-нибудь